• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

INSTALL/install.php

Go to the documentation of this file.
00001 <?php
00009 
00010 define('__PRAGYAN_CMS',')$!%^!%#^@');
00011 
00012 global $sourceFolder;
00013 global $scriptPath;
00014 global $URL_REWRITE;
00015 $sourceFolder = 'cms';
00016 $installFolder = '.';
00017 $URL_REWRITE = 'false';
00018 $userConfigs=array();
00019 $cmsFolder = "../$sourceFolder";
00020 $templateFolder = "$cmsFolder/templates/crystalx";
00021 $scriptPathWithFolder = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
00022 $scriptPath = substr($scriptPathWithFolder , 0, strrpos($scriptPathWithFolder , '/'));
00023 
00024 
00025 
00026 require_once($cmsFolder."/common.lib.php");
00027 define('CMS_SETUP', true);
00028 
00029 
00030 $installPageNumber = 2;
00031 $prerequisiteText = CheckPrerequisites();
00032 if ($prerequisiteText != '')
00033         $installPageNumber = 1;
00034 elseif (isset($_POST['btnSubmitSettings']))
00035         $installPageNumber = 3;
00036 
00037 if ($installPageNumber == 1) {
00038         $installPageContent = $prerequisiteText;
00039 }
00040 else if ($installPageNumber == 2) {
00041         include_once('settingsform.php');
00042         $installPageContent = $settingsForm;
00043                         
00044 }
00045 else if ($installPageNumber == 3) {
00046         $successImage = "<img src=\"$installFolder/images/instsuccess.png\" alt=\"Successful\" />";
00047         $errorImage = "<img src=\"$installFolder/images/insterror.png\" alt=\"Aborted\" />";
00048         $installationProgress = installCMS();
00049         $installationErrors = '';
00050         $installPageContent = '';
00051         for ($i = 0; $i < count($installationProgress); ++$i) {
00052                 $installPageContent .= "<tr><td width=\"100%\">{$installationProgress[$i][1]}</td><td>";
00053                 if ($installationProgress[$i][2] !== true) {
00054                         $installPageContent .= $errorImage;
00055                         if (isset($installationProgress[$i][3]))
00056                                 $installationErrors = $installationProgress[$i][3] . "<a href=\"javascript: history.back()\">Click here</a> to go back.</a>";
00057                 }
00058                 else
00059                         $installPageContent .= $successImage;
00060                 $installPageContent .= "</td></tr>\n";
00061         }
00062 
00063         
00064 
00065         $installPageContent = "<br /><table width=\"100%\" border=\"0\">\n $installPageContent </table>\n $installationErrors";
00066         if ($installationErrors == '') {
00067                 $installPageContent .= <<<HTTPDCONF
00068                 <b>Your installation is almost over. As a security measure, either delete the INSTALL folder or remove read permissions from it so that no-one else can access that folder.</b>
00069                 
00070                 
00071                         For Pragyan CMS to work, .htaccess needs to be supported your webserver. <br />
00072                         For this, the <b>AllowOverride</b> setting in the httpd.conf has to be made <i>Options FileInfo Limit</i> under the relevant <mono>&lt;Directory&gt;</mono> section.<br />
00073                         The default location of httpd.conf is <mono>/etc/httpd/conf/httpd.conf</mono>, but may be different for you according to your installation.
00074                         <br /><br />
00075                         Add the following lines in the httpd.conf of your webserver :
00076                         <pre><xmp>
00077                                 <Directory "$scriptPath">
00078                                         AllowOverride All
00079                                 </Directory>
00080                         </xmp></pre>
00081                         <p>If you have done this, <a href="../">click here</a> to go to the CMS.</p>
00082 HTTPDCONF;
00083         }
00084 }
00085 
00086 include_once('template.php');
00087 
00088 
00093 function installCMS() {
00094         global $URL_REWRITE;
00095         $installationSteps = 
00096                         array(
00097 
00098                                         array('loadConfigurationSettings', 'Loading Configuration Settings', false),
00099                                         array('checkDatabaseAccess', 'Checking Database Access', false),
00100                                         array('checkOpenidCurl','Checking if cURL needed and installed',false),
00101                                         array('importDatabase', 'Importing Database', false),
00102                                         array('saveHtaccess', 'Checking .htaccess Settings (for Pretty URLs)', false),
00103                                         array('saveConfigurationFile', 'Saving Configuration Settings to file', false)
00104                                         //array('indexSite', 'Indexing site', false)
00105                         );
00106         
00107                         
00108         
00109         
00110 
00111         for ($i = 0; $i < count($installationSteps); ++$i) { 
00112                 $installationProcedure = $installationSteps[$i][0];
00113 
00114                 $stepResult = $installationProcedure();
00115 
00117                 if($i==1 && OPENID_ENABLED!='true')
00118                         unset($installationSteps[2]);
00119                         
00121                 $installationSteps=array_values($installationSteps);
00122                 
00124                 if($i==1 && $URL_REWRITE=='false')
00125                         unset($installationSteps[count($installationSteps)-2]);
00126                 
00128                 $installationSteps=array_values($installationSteps);
00129 
00130                 if ($stepResult != '') {
00131                         $installationSteps[$i][] = $stepResult;
00132 
00133                         return $installationSteps;
00134                 }
00135                 $installationSteps[$i][2] = true;
00136 
00137         }
00138         return $installationSteps;
00139 }
00144 function checkOpenidCurl(){
00145   if(OPENID_ENABLED=='true')//this function works only if uesr wanted to select OPENID
00146     {
00147       
00148       if (iscurlinstalled()) //check if curl is enabled
00149         return '';
00150       else
00151         {
00152           global $curl_message;
00153           return "<p><b>Error:</b>$curl_message</p>";
00154         }
00155     }
00156   else
00157     {
00158       return '';
00159     }
00160 }
00161           
00162 
00167 function loadConfigurationSettings() {
00168         global $URL_REWRITE;
00169         global $userConfigs;
00170         
00171         $configurationMap = array(
00172                         'txtMySQLServerHost' => 'MYSQL_SERVER',
00173                         'txtMySQLUsername' => 'MYSQL_USERNAME',
00174                         'txtMySQLPassword' => 'MYSQL_PASSWORD',
00175                         'txtMySQLDatabase' => 'MYSQL_DATABASE',
00176                         'txtMySQLTablePrefix' => 'MYSQL_DATABASE_PREFIX',
00177                         'txtAdminUsername' => 'ADMIN_USERNAME',
00178                         'txtAdminEmail' => 'ADMIN_EMAIL',
00179                         'txtAdminFullname' => 'ADMIN_FULLNAME',
00180                         'txtAdminPassword' => 'ADMIN_PASSWORD',
00181                         'optSendVerification' => 'SEND_MAIL_ON_REGISTRATION',
00182                         'optDefaultUserActive' => 'DEFAULT_USER_ACTIVATE',
00183                         'txtCMSMailId' => 'CMS_EMAIL',
00184                         'txtCMSTitle' => 'CMS_TITLE',
00185                         'selTemplate' => 'CMS_TEMPLATE',
00186                         'txtUploadLimit' => 'UPLOAD_LIMIT',
00187                         'optEnableOpenID' => 'OPENID_ENABLED',
00188                         'txtCookieTimeout' => 'cookie_timeout',
00189                         'selErrorReporting' => 'error_level',
00190                         'optEnableIMAP' => 'AUTH_IMAP_STATUS',
00191                         'txtIMAPServerAddress' => 'AUTH_IMAP_SERVER',
00192                         'txtIMAPPort' => 'AUTH_IMAP_PORT',
00193                         'txtIMAPUserDomain' => 'AUTH_IMAP_DOMAIN',
00194                         'optEnableLDAP' => 'AUTH_LDAP_STATUS',
00195                         'txtLDAPServerAddress' => 'AUTH_LDAP_SERVER',
00196                         'txtLDAPSearchGroup' => 'AUTH_LDAP_SEARCHGROUP',
00197                         'txtLDAPUserDomain' => 'AUTH_LDAP_DOMAIN',
00198                         'optEnableADS' => 'AUTH_ADS_STATUS',
00199                         'txtADSServerAddress' => 'AUTH_ADS_SERVER',
00200                         'txtADSNetworkName' => 'AUTH_ADS_NETWORK',
00201                         'txtADSUserDomain' => 'AUTH_ADS_DOMAIN',
00202                         'txtMySQLServerPort' => 'MYSQL_PORT',
00203                         'optURLRewrite' => 'URL_REWRITE'
00204                         
00205         );
00206         
00207         foreach ($configurationMap as $postVariableName => $configVariableName) {
00208                 if (substr($postVariableName, 0, 3) == "opt") {
00209                         ${$configVariableName} = (isset($_POST[$postVariableName]) && $_POST[$postVariableName] == "Yes") ? 'true' : 'false';
00210                 }
00211                 else {
00212                         ${$configVariableName} = isset($_POST[$postVariableName]) ? escape($_POST[$postVariableName]) : '';
00213                 }
00214                 $userConfigs[$configVariableName]=${$configVariableName};
00215                         
00216         }
00217         if($MYSQL_PORT!="") $MYSQL_SERVER.=":$MYSQL_PORT";
00218         
00219         global $cmsFolder;
00220 
00221 
00222         $c = 0;
00223         foreach ($configurationMap as $postVariableName => $configVariableName) {
00224 
00225                 define ($configVariableName, ${$configVariableName});
00226                 if (++$c == 16) //this avoids DEFINEing all the config whichh are not to be written in database
00227                         break;
00228         }
00229         
00230         return '';
00231 }
00232 
00233 function saveConfigurationFile() {
00234 
00235         global $userConfigs;
00236         global $cmsFolder;
00237         
00238         extract($userConfigs);
00239         
00240         $configFileText = '';
00241         require_once('config.inc-dist.php');
00242         $writeHandle = @fopen("$cmsFolder/config.inc.php", 'w');
00243         if (!$writeHandle)
00244                 return 'Could not write to config.inc.php. Please make sure that the file is writable.';
00245 
00246         fwrite($writeHandle, $configFileText);
00247         fclose($writeHandle);
00248         
00249         $writeHandle = @fopen("$cmsFolder/modules/search/settings/database.php",'w');
00250         if(!$writeHandle)
00251                 return "Could not write to $cmsFolder/modules/search/settings/database.php. Please make sure that the file is writable.";
00252         
00253         fwrite($writeHandle, $searchConfigFileText);
00254         fclose($writeHandle);
00255         return '';
00256 }
00257 
00258 function checkDatabaseAccess() {
00259         $dbaccessInfo = '';
00260         $dbaccessErrorTip = <<<WHATEVER
00261                         <p>To create a database and a user with all priviliges to that database, run the following queries after replacing <b>pragyandatabase</b>, <b>localhost</b>, <b>pragyanuser</b> and <b>pragyanpassword</b> as required. </p>
00262                         <pre>CREATE DATABASE `pragyandatabase`;
00263 CREATE USER 'pragyanuser'@'localhost' IDENTIFIED BY 'pragyanpassword';
00264 GRANT ALL PRIVILEGES ON `pragyandatabase` . * TO 'pragyanuser'@'localhost';</pre>
00265                         <p>After you run these queries successfully in your MySQL client, please run this install script again.</p>
00266 WHATEVER;
00267 
00268         $dbhost=MYSQL_SERVER;
00269         $dbname=MYSQL_DATABASE;
00270 
00271         $dbuser=MYSQL_USERNAME;
00272         $dbpasswd=MYSQL_PASSWORD;
00273         $dblink=mysql_connect($dbhost,$dbuser,$dbpasswd);
00274         if($dblink==false)
00275         {
00276                 $dbaccessInfo.="<p><b>Error:</b> Pragyan CMS could not connect to database on '$dbhost' using username '$dbuser'. Please check the username/password you provided.</p>$dbpasswd";
00277                 return $dbaccessInfo . $dbaccessErrorTip;
00278         }
00279         $db=mysql_select_db($dbname);
00280         if($db==false)
00281         {
00282                 $dbaccessInfo.="<p><b>Error:</b> Pragyan CMS could not select the database '$dbname'.<br/> Please make sure the database exists and the user $dbuser has permissions over it.</p>";
00283                         return $dbaccessInfo . $dbaccessErrorTip;
00284         }
00285         $res=mysql_query("CREATE TABLE IF NOT EXISTS `testtable948823` ( `testuserid` int(10) )");
00286         if($res==false)
00287         {
00288                 $dbaccessInfo.="<p><b>Error:</b> The User '$dbuser' does not have permissions to CREATE tables in '$dbname'.</p>";
00289                 return $dbaccessInfo . $dbaccessErrorTip;
00290         }
00291         $res=mysql_query("INSERT INTO `testtable948823` VALUES (123)");
00292         if($res==false)
00293         {
00294                 $dbaccessInfo.="<p><b>Error:</b> The User '$dbuser' does not have permissions to INSERT values in tables of database '$dbname'.</p>";
00295                 return $dbaccessInfo . $dbaccessErrorTip;
00296         }
00297         $res=mysql_query("UPDATE `testtable948823` SET testuserid=0");
00298         if($res==false)
00299         {
00300                 $dbaccessInfo.="<p><b>Error:</b> The User '$dbuser' does not have permissions to UPDATE values in tables of database '$dbname'.</p>";
00301                 return $dbaccessInfo . $dbaccessErrorTip;
00302         }
00303         $res=mysql_query("SELECT * FROM `testtable948823`");
00304         if($res==false)
00305         {
00306                 $dbaccessInfo.="<p><b>Error:</b> The User '$dbuser' does not have permissions to SELECT values in tables of database '$dbname'.</p>";
00307                 return $dbaccessInfo . $dbaccessErrorTip;
00308         }
00309         $res=mysql_query("DROP TABLE `testtable948823`");
00310         if($res==false)
00311         {
00312                 $dbaccessInfo.="<p><b>Error:</b> The User '$dbuser' does not have permissions to DROP tables of database '$dbname'.</p>";
00313                 return $dbaccessInfo . $dbaccessErrorTip;
00314         }
00315         return '';
00316 }
00317 
00318 function importDatabase() {
00319         global $installFolder, $URL_REWRITE;
00320 
00321         mysql_connect(MYSQL_SERVER, MYSQL_USERNAME, MYSQL_PASSWORD);
00322         mysql_select_db(MYSQL_DATABASE);
00323 
00324         $handle = @fopen($installFolder."/pragyan_structure.sql", "r");
00325         $query = '';
00326         if ($handle) {
00327           while (!feof($handle)) {
00328             $buffer = fgets($handle, 4096);
00329             if (strpos($buffer,"--") !== 0)
00330               $query.=$buffer;
00331           }
00332           fclose($handle);
00333         }
00334         $query = str_replace("pragyanV3_",MYSQL_DATABASE_PREFIX,$query);
00335         $singlequeries = explode(";\n",$query);
00336         foreach ($singlequeries as $singlequery) {
00337                 if (trim($singlequery)!="") {
00338                         $result1 = mysql_query($singlequery);
00339                         if (!$result1) {
00340                                 $output = "<h3>Error:</h3><pre>".$singlequery."</pre>\n<br/>Unable to create structure. ".mysql_error();
00341                                 return $output;
00342                         }
00343                 }
00344         }
00345         $error = include 'searchStructure.php';
00346         if($error != '')
00347                 return $error;
00348         $handle = @fopen($installFolder."/pragyan_inserts.sql", "r");
00349         if ($handle) {
00350                 while (!feof($handle)) {
00351                         $buffer = fgets($handle, 4096);
00352                         if (strpos($buffer,"--")!==0)
00353                                 $query.=$buffer;
00354                 }
00355                 fclose($handle);
00356         }
00357         $query = str_replace("pragyanV3_",MYSQL_DATABASE_PREFIX,$query);
00358         $singlequeries = explode(";\n",$query);
00359         foreach ($singlequeries as $singlequery) {
00360                 if (trim($singlequery)!="") {
00361                         $result1 = mysql_query($singlequery);
00362                         if (!$result1) {
00363                         $output = "<h3>Error:</h3><pre>".$singlequery."</pre>\n<br/>Unable to import the rows. " . mysql_error();
00364                         return $output;
00365                         }
00366                 }
00367         }
00368         $DEFAULT_USER_ACTIVATE=(DEFAULT_USER_ACTIVATE=="true"?1:0);
00369         $SEND_MAIL_ON_REGISTRATION=(SEND_MAIL_ON_REGISTRATION=="true"?1:0);
00370         
00371         setGlobalSettingByAttribute("cms_title",CMS_TITLE);
00372         setGlobalSettingByAttribute("cms_email",CMS_EMAIL);
00373         setGlobalSettingByAttribute("default_template",CMS_TEMPLATE);
00374         setGlobalSettingByAttribute("url_rewrite",$URL_REWRITE);
00375         setGlobalSettingByAttribute("default_user_activate",$DEFAULT_USER_ACTIVATE);
00376         setGlobalSettingByAttribute("default_mail_verify",$SEND_MAIL_ON_REGISTRATION);
00377         setGlobalSettingByAttribute("upload_limit",UPLOAD_LIMIT);
00378         setGlobalSettingByAttribute("cms_desc",CMS_TITLE);
00379         setGlobalSettingByAttribute("cms_keywords",CMS_TITLE);
00380         setGlobalSettingByAttribute("reindex_frequency","2");
00381         setGlobalSettingByAttribute("allow_login","1");
00382         setGlobalSettingByAttribute("cms_footer","&copy; 2010 - powered by <a href=\"http://sourceforge.net/projects/pragyan\" title=\"Praygan CMS\">Pragyan CMS v3.0</a>");
00383         setGlobalSettingByAttribute("openid_enabled",OPENID_ENABLED);
00384         
00385 
00386         $query="INSERT IGNORE INTO `".MYSQL_DATABASE_PREFIX."users` (`user_id`,`user_name`,`user_email`,`user_fullname`,`user_password`,`user_regdate`,`user_lastlogin`,`user_activated`,`user_loginmethod`) VALUES (
00387         1,'".ADMIN_USERNAME."','".ADMIN_EMAIL."','".ADMIN_FULLNAME."','".md5(ADMIN_PASSWORD)."',NOW(),'',1,'db')";
00388         mysql_query($query);
00389         global $cmsFolder;
00390         $templates=scandir($cmsFolder.'/templates');
00391 
00392         foreach($templates as $tdir)
00393         {
00394 
00395                 if(is_dir($cmsFolder.'/templates/'.$tdir) && $tdir[0]!='.' && $tdir!="common")
00396                 {
00397 
00398                         $query="INSERT IGNORE INTO `".MYSQL_DATABASE_PREFIX."templates` (`template_name`) VALUES ('$tdir')";
00399                         mysql_query($query);
00400                 }
00401         }
00402         
00403         return '';
00404 }
00405 
00424 function checkLocationAccess($path)
00425 {
00426         $code=0;
00427         if(is_file($path))
00428         {
00429                 $code+=1;
00430                 $code+=is_writable($path)?4:8;
00431         }
00432         else if(is_dir($path))
00433         {
00434                 $code+=2;
00435                 $testFolder=@fopen($path."/testfolder",'w');
00436                 $code+=($testFolder)?4:8;
00437                 if($testFolder)
00438                 {
00439                         fclose($testFolder);
00440                         unlink($path."/testfolder");
00441                 }
00442         }
00443         else $code+=16;
00444         return $code;
00445 }
00446 
00451 function CheckPrerequisites() {
00452         global $sourceFolder;
00453         global $scriptPath;
00454         
00455         $cmsfolder = "$scriptPath/$sourceFolder";
00456         
00457         $checklist=array( 
00458                         "$cmsfolder" => "folder", 
00459                         "$cmsfolder/uploads" => "folder",
00460                         "$cmsfolder/templates" => "folder",
00461                         "$cmsfolder/widgets" => "folder",
00462                         "$cmsfolder/languages" => "folder",
00463                         "$cmsfolder/modules" => "folder",
00464                         "$cmsfolder/modules/search/settings/database.php" => "file",
00465                         );
00466         
00467         $checklist2=array();
00468         
00469         foreach($checklist as $path=>$type)
00470         {
00471                 switch(checkLocationAccess($path))
00472                 {
00473                         case 9 : $prereq.="<li><p>Pragyan CMS doesn't have write permissions over the file <b>$path</b>.</p></li>"; break;
00474                         case 10 : $prereq.="<li><p>Pragyan CMS doesn't have write permissions over the folder <b>$path</b>.</p></li>"; break;
00475                         case 16 : 
00476                         
00477                                 $trycreate=($type=="file")?(touch($path)&&chmod($path,0755)):mkdir($path);
00478                                 if($trycreate)
00479                                         $checklist2[$path]=$type;
00480                                 else
00481                                         $prereq.="<li><p>The following $type is missing : <b>$path</b> and Pragyan CMS was not able to create it. Please create the $type manually and make sure Pragyan CMS has write permissions over it.</p></li>"; 
00482                                 break;
00483                 }
00484         }
00485         foreach($checklist2 as $path=>$type)
00486         {
00487                 switch(checkLocationAccess($path))
00488                 {
00489                         case 9 : $prereq.="<li><p>Pragyan CMS doesn't have write permissions over the file <b>$path</b>.</p></li>"; break;
00490                         case 10 : $prereq.="<li><p>Pragyan CMS doesn't have write permissions over the folder <b>$path</b>.</p></li>"; break;
00491                         case 16 : 
00492                         
00493                                 $trycreate=($type=="file")?touch($path):mkdir($path);
00494                                 if($trycreate)
00495                                         $checklist2[$path]=$type;
00496                                 else
00497                                         $prereq.="<li><p>The following $type is missing : <b>$path</b> and Pragyan CMS was not able to create it. Please create the $type manually and make sure Pragyan CMS has write permissions over it.</p></li>";
00498                                 break;
00499                 }
00500         }
00501         $http_htaccess= getenv('HTTP_HTACCESS')=='On' ? true : false ;
00502         
00503         if(!$http_htaccess)
00504         {
00505             $prereq.="<li><p>.htaccess not enabled </p></li>";
00506             $prereq .= <<<HTTPMSG
00507             For Pragyan CMS to work, .htaccess needs to be supported your webserver. <br />
00508                         For this, the <b>AllowOverride</b> setting in the httpd.conf has to be made <i>Options FileInfo Limit</i> under the relevant <mono>&lt;Directory&gt;</mono> section.<br />
00509                         The default location of httpd.conf is <mono>/etc/httpd/conf/httpd.conf</mono>, but may be different for you according to your installation.
00510                         <br /><br />
00511                         Add the following lines in the httpd.conf of your webserver :
00512                         <pre><xmp>
00513                                 <Directory "$scriptPath">
00514                                         AllowOverride All
00515                                 </Directory>
00516                         </xmp></pre>
00517                         <p>If you have done this, <a href="../">click here</a> to go to the CMS.</p>
00518 HTTPMSG;
00519         }
00520         
00521         if ($prereq != '') {
00522                 $prereq = "<p>The following prerequisite(s) need to be resolved before Pragyan CMS can continue installation.</p>\n<ul>\n$prereq\n</ul>";
00523                 $prereq .= '<p>Please make the necessary changes, and <a href="javascript: location.reload(true)">click here</a> to refresh this page.</p>';
00524                 $prereq .= <<<MSG
00525 <hr/>
00526         <p>Pragyan CMS should have full write-access to its root installation directory. In your case it is : <b>$scriptPath</b>.<br/>
00527         Please make sure the installation directory is writable by your webserver user. On a <i>linux</i> server, run the following commands as root:
00528         <pre>chown -R &lt;httpd-process-user&gt; $scriptPath</pre>
00529 where &lt;httpd-process-user&gt; is the default user for your webserver process. In most cases, it is either 'www-data' or 'apache'.
00530         <br/><br/>OR if you don't know your webserver process user and you're also not so concerned about security, execute the following command as root :
00531         <br /><pre>chmod -R 777 $scriptPath</pre></p>
00532 MSG;
00533         }
00534 
00535         clearstatcache();
00536         return $prereq;
00537 }
00538 
00542 function saveHtaccess() {
00543 
00544         $urlRequestRootWithFolder = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
00545         $urlRequestRoot = substr($urlRequestRootWithFolder , 0, strrpos($urlRequestRootWithFolder , '/'));
00546         $urlRequestRoot = ($urlRequestRoot==""?"/":$urlRequestRoot);
00547         $scriptPathWithFolder = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
00548         $scriptPath = substr($scriptPathWithFolder , 0, strrpos($scriptPathWithFolder , '/'));
00549 
00550         $errorMessage = <<<HTACCESSERROR
00551                         <p>Could not save .htaccess file.</p>
00552                         <p>Please ensure that the .htaccess file in the Pragyan CMS installation folder exists and is writable.</p>
00553                         <p>You can change permissions back to the way it was, after the installation completes.</p>
00554                         <p><a href="javascript: location.reload(true)">Click here</a> to refresh this page.</p>
00555 HTACCESSERROR;
00556 
00557         $htaccessdist = "../htaccess-dist";
00558         $htaccessFile = "../.htaccess";
00559         
00560         copy($htaccessdist,$htaccessFile);
00561         
00562         $htaccessHandle = fopen($htaccessFile, 'r');
00563         if (!$htaccessHandle)
00564                 return $errorMessage;
00565 
00566         $lines = file('../.htaccess');
00567         $htaccessHandle = fopen($htaccessFile, 'w');
00568 
00569         if (!$lines || !$htaccessHandle) {
00570                 return $errorMessage;
00571         }
00572 
00573         for ($i = 0; $i < count($lines); ++$i) {
00574                 if (trim($lines[$i]) == '#BASEDIRECTORY') {
00575                         fwrite($htaccessHandle, "#BASEDIRECTORY\n");
00576                         fwrite($htaccessHandle, "RewriteBase $urlRequestRoot\n");
00577                         fwrite($htaccessHandle, "RewriteCond %{REQUEST_URI} ^$urlRequestRoot/\$\n");
00578                         $i += 2;
00579                 }
00580                 if (trim($lines[$i]) == '#REWRITEENGINE') {
00581                         fwrite($htaccessHandle, "#REWRITEENGINE\n");
00582                         fwrite($htaccessHandle, "RewriteEngine On\n");
00583                         $i += 1;
00584                 }
00585                 else
00586                         fwrite($htaccessHandle, $lines[$i]);
00587         }
00588         fclose($htaccessHandle);
00589 
00590         return '';
00591 }

Generated on Mon Mar 14 2011 05:35:30 for Pragyan CMS by  doxygen 1.7.1