[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 general.php

Zen Cart 源代码 general.php




下载文件

文件名: general.php
文件类型: PHP文件
文件大小: 41.42 KiB
MD5: 40a575cef10b1134a8d6a42466eda845

general.php - 关闭高亮
  1. <?php
  2. /**
  3.  * general functions used by the installer
  4.  * @package Installer
  5.  * @access private
  6.  * @copyright Copyright 2003-2012 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version GIT: $Id: Author: Ian Wilson  Tue Aug 14 14:56:11 2012 +0100 Modified in v1.5.1 $
  10.  */
  11.  
  12.   if (!defined('TABLE_UPGRADE_EXCEPTIONS')) define('TABLE_UPGRADE_EXCEPTIONS','upgrade_exceptions');
  13.  
  14.   function zen_not_null($value) {
  15.     if (is_array($value)) {
  16.       if (sizeof($value) > 0) {
  17.         return true;
  18.       } else {
  19.         return false;
  20.       }
  21.     } else {
  22.       if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
  23.         return true;
  24.       } else {
  25.         return false;
  26.       }
  27.     }
  28.   }
  29.  
  30.   function zen_output_string($string, $translate = false, $protected = false) {
  31.     if ($protected == true) {
  32.       return htmlspecialchars($string, ENT_COMPAT, CHARSET, TRUE);
  33.     } else {
  34.       if ($translate == false) {
  35.         return zen_parse_input_field_data($string, array('"' => '&quot;'));
  36.       } else {
  37.         return zen_parse_input_field_data($string, $translate);
  38.       }
  39.     }
  40.   }
  41.  
  42. ////
  43.   function zen_db_input($string) {
  44.     return addslashes($string);
  45.   }
  46.  
  47. ////
  48.   function zen_parse_input_field_data($data, $parse) {
  49.     return strtr(trim($data), $parse);
  50.   }
  51.  
  52. function setInputValue($input, $constant, $default) {
  53.   if (isset($input)) {
  54.     define($constant, $input);
  55.   } else {
  56.     define($constant, $default);
  57.   }
  58. }
  59.  
  60. function setRadioChecked($input, $constant, $default) {
  61.   if ($input == '') {
  62.   $input = $default;
  63.   }
  64.   if ($input == 'true') {
  65.   define($constant . '_FALSE', '');
  66.   define($constant . '_TRUE', 'checked="checked" ');
  67.   } else {
  68.   define($constant . '_FALSE', 'checked="checked" ');
  69.   define($constant . '_TRUE', '');
  70.   }
  71. }
  72.  
  73. function setSelected($input, $selected) {
  74.   if ($input == $selected) {
  75.     return ' selected="selected"';
  76.   }
  77. }
  78. function executeSql($sql_file, $database, $table_prefix = '', $isupgrade=false) {
  79.   $debug=false;
  80.   if (!defined('DB_PREFIX')) define('DB_PREFIX', $table_prefix);
  81. //    echo 'start SQL execute';
  82.   global $db;
  83.  
  84.   $ignored_count=0;
  85.   $ignore_line=false;
  86.   $results=0;
  87.   $string='';
  88.   $result='';
  89.   $collateSuffix = '';
  90.   $errors=array();
  91.  
  92.   // prepare for upgrader processing
  93.   if ($isupgrade) zen_create_upgrader_table(); // only creates table if doesn't already exist
  94.  
  95.   if (version_compare(PHP_VERSION, 5.4, '>=') || !get_cfg_var('safe_mode')) {
  96.     @set_time_limit(1200);
  97.   }
  98.  
  99.   $counter = 0;
  100.   $lines = file($sql_file);
  101.   $newline = '';
  102.   $lines_to_keep_together_counter=0;
  103. //  $saveline = '';
  104.   foreach ($lines as $line) {
  105.     $line = trim($line);
  106. //    $line = $saveline . $line;
  107.     $keep_together = 1; // count of number of lines to treat as a single command
  108.  
  109.      // split the line into words ... starts at $param[0] and so on.  Also remove the ';' from end of last param if exists
  110.      $param=explode(" ",(substr($line,-1)==';') ? substr($line,0,strlen($line)-1) : $line);
  111.      if (!isset($param[4])) $param[4] = '';
  112.      if (!isset($param[5])) $param[5] = '';
  113.  
  114.       // The following command checks to see if we're asking for a block of commands to be run at once.
  115.       // Syntax: #NEXT_X_ROWS_AS_ONE_COMMAND:6     for running the next 6 commands together (commands denoted by a ;)
  116.       if (substr($line,0,28) == '#NEXT_X_ROWS_AS_ONE_COMMAND:') $keep_together = substr($line,28);
  117.       if (substr($line,0,1) != '#' && substr($line,0,1) != '-' && $line != '') {
  118. //        if ($table_prefix != -1) {
  119. //echo '*}'.$line.'<br>';
  120.  
  121.           $line_upper=strtoupper($line);
  122.           switch (true) {
  123.           case (substr($line_upper, 0, 21) == 'DROP TABLE IF EXISTS '):
  124.             $line = 'DROP TABLE IF EXISTS ' . $table_prefix . substr($line, 21);
  125.             break;
  126.           case (substr($line_upper, 0, 11) == 'DROP TABLE ' && $param[2] != 'IF'):
  127.             if (!$checkprivs = zen_check_database_privs('DROP')) $result=sprintf(REASON_NO_PRIVILEGES,'DROP');
  128.             if (!zen_table_exists($param[2]) || zen_not_null($result)) {
  129.               zen_write_to_upgrade_exceptions_table($line, (zen_not_null($result) ? $result : sprintf(REASON_TABLE_DOESNT_EXIST,$param[2])), $sql_file);
  130.               $ignore_line=true;
  131.               $result=(zen_not_null($result) ? $result : sprintf(REASON_TABLE_DOESNT_EXIST,$param[2])); //duplicated here for on-screen error-reporting
  132.               break;
  133.             } else {
  134.               $line = 'DROP TABLE ' . $table_prefix . substr($line, 11);
  135.             }
  136.             break;
  137.           case (substr($line_upper, 0, 13) == 'CREATE TABLE '):
  138.             // check to see if table exists
  139.             $table = (strtoupper($param[2].' '.$param[3].' '.$param[4]) == 'IF NOT EXISTS') ? $param[5] : $param[2];
  140.             $result=zen_table_exists($table);
  141.             if ($result==true) {
  142.               $ignore_line=true;
  143.               if (strtoupper($param[2].' '.$param[3].' '.$param[4]) != 'IF NOT EXISTS') {
  144.                 zen_write_to_upgrade_exceptions_table($line, sprintf(REASON_TABLE_ALREADY_EXISTS,$table), $sql_file);
  145.                 $result=sprintf(REASON_TABLE_ALREADY_EXISTS,$table); //duplicated here for on-screen error-reporting
  146.               }
  147.               break;
  148.             } else {
  149.               $line = (strtoupper($param[2].' '.$param[3].' '.$param[4]) == 'IF NOT EXISTS') ? 'CREATE TABLE IF NOT EXISTS ' . $table_prefix . substr($line, 27) : 'CREATE TABLE ' . $table_prefix . substr($line, 13);
  150.               $collateSuffix = (strtoupper($param[3]) == 'AS' || (isset($param[6]) && strtoupper($param[6]) == 'AS')) ? '' : ' COLLATE ' . DB_CHARSET . '_general_ci';
  151.             }
  152.             break;
  153.           case (substr($line_upper, 0, 13) == 'REPLACE INTO '):
  154.             //check to see if table prefix is going to match
  155.             if (!$tbl_exists = zen_table_exists($param[2])) $result=sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!';
  156.             // check to see if INSERT command may be safely executed for "configuration" or "product_type_layout" tables
  157.             if (($param[2]=='configuration'       && ($result=zen_check_config_key($line))) or
  158.                 ($param[2]=='product_type_layout' && ($result=zen_check_product_type_layout_key($line))) or
  159.                 ($param[2]=='configuration_group' && ($result=zen_check_cfggroup_key($line))) or
  160.                 (!$tbl_exists)    ) {
  161.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  162.               $ignore_line=true;
  163.               break;
  164.             } else {
  165.               $line = 'REPLACE INTO ' . $table_prefix . substr($line, 13);
  166.             }
  167.             break;
  168.           case (substr($line_upper, 0, 12) == 'INSERT INTO '):
  169.             //check to see if table prefix is going to match
  170.             if (!$tbl_exists = zen_table_exists($param[2])) $result=sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!';
  171.             // check to see if INSERT command may be safely executed for "configuration" or "product_type_layout" tables
  172.             if (($param[2]=='configuration'       && ($result=zen_check_config_key($line))) or
  173.                 ($param[2]=='product_type_layout' && ($result=zen_check_product_type_layout_key($line))) or
  174.                 ($param[2]=='configuration_group' && ($result=zen_check_cfggroup_key($line))) or
  175.                 (!$tbl_exists)    ) {
  176.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  177.               $ignore_line=true;
  178.               break;
  179.             } else {
  180.               $line = 'INSERT INTO ' . $table_prefix . substr($line, 12);
  181.             }
  182.             break;
  183.           case (substr($line_upper, 0, 19) == 'INSERT IGNORE INTO '):
  184.             //check to see if table prefix is going to match
  185.             if (!$tbl_exists = zen_table_exists($param[3])) {
  186.               $result=sprintf(REASON_TABLE_NOT_FOUND,$param[3]).' CHECK PREFIXES!';
  187.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  188.               $ignore_line=true;
  189.               break;
  190.             } else {
  191.               $line = 'INSERT IGNORE INTO ' . $table_prefix . substr($line, 19);
  192.             }
  193.             break;
  194.             case (substr($line_upper, 0, 19) == 'ALTER IGNORE TABLE '):
  195.             // check to see if ALTER IGNORE command may be safely executed
  196.             if ($result=zen_check_alter_command($param)) {
  197.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  198.               $ignore_line=true;
  199.               break;
  200.             } else {
  201.               $line = 'ALTER IGNORE TABLE ' . $table_prefix . substr($line, 19);
  202.             }
  203.             break;
  204.             case (substr($line_upper, 0, 12) == 'ALTER TABLE '):
  205.             //if (ZC_UPG_DEBUG3==true) echo 'ALTER -- Table check ('.$param[2].')' .'<br>';
  206.             // check to see if ALTER command may be safely executed
  207.             if ($result=zen_check_alter_command($param)) {
  208.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  209.               $ignore_line=true;
  210.               break;
  211.             } else {
  212.               $line = 'ALTER TABLE ' . $table_prefix . substr($line, 12);
  213.             }
  214.             break;
  215.           case (substr($line_upper, 0, 15) == 'TRUNCATE TABLE '):
  216.             // check to see if TRUNCATE command may be safely executed
  217.             if (!$tbl_exists = zen_table_exists($param[2])) {
  218.               $result=sprintf(REASON_TABLE_NOT_FOUND,$param[3]).' CHECK PREFIXES!';
  219.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  220.               $ignore_line=true;
  221.               break;
  222.             } else {
  223.               $line = 'TRUNCATE TABLE ' . $table_prefix . substr($line, 15);
  224.             }
  225.             break;
  226.           case (substr($line_upper, 0, 13) == 'RENAME TABLE '):
  227.             // RENAME TABLE command cannot be parsed unless it is split into two lines
  228.             if (isset($param[3]) && $param[3] != '') {
  229.               zen_write_to_upgrade_exceptions_table($line, 'RENAME TABLE command must be split onto 2 rows for proper parsing.  Or use phpMyAdmin instead.', $sql_file);
  230.               $result=sprintf('RENAME TABLE [%s] command must be split onto 2 rows for proper parsing.',$param[2]).' CHECK PREFIXES!';
  231.               $ignore_line=true;
  232.             }
  233.             //check to see if table prefix is going to match
  234.             if (!$tbl_exists = zen_table_exists($param[2])) {
  235.               zen_write_to_upgrade_exceptions_table($line, sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!', $sql_file);
  236.               $result=sprintf('RENAME TABLE problem: ' . REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!';
  237.               $ignore_line=true;
  238.               break;
  239.             } else {
  240.               $line = 'RENAME TABLE ' . $table_prefix . substr($line, 13);
  241.             }
  242.             break;
  243.           case (substr($line_upper, 0, 3) == 'TO '):
  244.             if (!isset($param[1]) || $param[1] == '') {
  245.               zen_write_to_upgrade_exceptions_table($line, 'RENAME TABLE command must be split onto 2 rows (with TO clause on 2nd line) for proper parsing.  Or use phpMyAdmin instead.', $sql_file);
  246.               $result=sprintf('RENAME TABLE problem: %s' ,$param[1]).' CHECK PREFIXES!';
  247.               $ignore_line=true;
  248.             } else {
  249.               $line = 'TO ' . $table_prefix . substr($line, 3);
  250.             }
  251.             break;
  252.           case (substr($line_upper, 0, 7) == 'UPDATE '):
  253.             //check to see if table prefix is going to match
  254.             if (!$tbl_exists = zen_table_exists($param[1])) {
  255.               zen_write_to_upgrade_exceptions_table($line, sprintf(REASON_TABLE_NOT_FOUND,$param[1]).' CHECK PREFIXES!', $sql_file);
  256.               $result=sprintf(REASON_TABLE_NOT_FOUND,$param[1]).' CHECK PREFIXES!';
  257.               $ignore_line=true;
  258.               break;
  259.             } else {
  260.               $line = 'UPDATE ' . $table_prefix . substr($line, 7);
  261.             }
  262.             break;
  263.           case (substr($line_upper, 0, 14) == 'UPDATE IGNORE '):
  264.             //check to see if table prefix is going to match
  265.             if (!$tbl_exists = zen_table_exists($param[2])) {
  266.               zen_write_to_upgrade_exceptions_table($line, sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!', $sql_file);
  267.               $result=sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!';
  268.               $ignore_line=true;
  269.               break;
  270.             } else {
  271.               $line = 'UPDATE IGNORE ' . $table_prefix . substr($line, 14);
  272.             }
  273.             break;
  274.           case (substr($line_upper, 0, 12) == 'DELETE FROM '):
  275.             $line = 'DELETE FROM ' . $table_prefix . substr($line, 12);
  276.             break;
  277.           case (substr($line_upper, 0, 11) == 'DROP INDEX '):
  278.             // check to see if DROP INDEX command may be safely executed
  279.             if ($result=zen_drop_index_command($param)) {
  280.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  281.               $ignore_line=true;
  282.               break;
  283.             } else {
  284.               $line = 'DROP INDEX ' . $param[2] . ' ON ' . $table_prefix . $param[4];
  285.             }
  286.             break;
  287.           case (substr($line_upper, 0, 13) == 'CREATE INDEX ' || (strtoupper($param[0])=='CREATE' && strtoupper($param[2])=='INDEX')):
  288.             // check to see if CREATE INDEX command may be safely executed
  289.             if ($result=zen_create_index_command($param)) {
  290.               zen_write_to_upgrade_exceptions_table($line, $result, $sql_file);
  291.               $ignore_line=true;
  292.               break;
  293.             } else {
  294.               if (strtoupper($param[1])=='INDEX') {
  295.                 $line = trim('CREATE INDEX ' . $param[2] .' ON '. $table_prefix . implode(' ',array($param[4],$param[5],$param[6],$param[7],$param[8],$param[9],$param[10],$param[11],$param[12],$param[13])) ).';'; // add the ';' back since it was removed from $param at start
  296.               } else {
  297.                 $line = trim('CREATE '. $param[1] .' INDEX ' .$param[3]. ' ON '. $table_prefix . implode(' ',array($param[5],$param[6],$param[7],$param[8],$param[9],$param[10],$param[11],$param[12],$param[13])) ); // add the ';' back since it was removed from $param at start
  298.               }
  299.             }
  300.             break;
  301.           case (substr($line_upper, 0, 7) == 'SELECT ' && substr_count($line,'FROM ')>0):
  302.             $line = str_replace('FROM ','FROM '. $table_prefix, $line);
  303.             break;
  304.           case (substr($line_upper, 0, 10) == 'LEFT JOIN '):
  305.             $line = 'LEFT JOIN ' . $table_prefix . substr($line, 10);
  306.             break;
  307.           case (substr($line_upper, 0, 5) == 'FROM '):
  308.             if (substr_count($line,',')>0) { // contains FROM and a comma, thus must parse for multiple tablenames
  309.               $tbl_list = explode(',',substr($line,5));
  310.               $line = 'FROM ';
  311.               foreach($tbl_list as $val) {
  312.                 $line .= $table_prefix . trim($val) . ','; // add prefix and comma
  313.               } //end foreach
  314.               if (substr($line,-1)==',') $line = substr($line,0,(strlen($line)-1)); // remove trailing ','
  315.             } else { //didn't have a comma, but starts with "FROM ", so insert table prefix
  316.               $line = str_replace('FROM ', 'FROM '.$table_prefix, $line);
  317.             }//endif substr_count(,)
  318.             break;
  319.           default:
  320.             break;
  321.           } //end switch
  322. //        } // endif $table_prefix
  323.         $newline .= $line . ' ';
  324.  
  325.         if ( substr($line,-1) ==  ';') {
  326.           //found a semicolon, so treat it as a full command, incrementing counter of rows to process at once
  327.           if (substr($newline,-1)==' ') $newline = substr($newline,0,(strlen($newline)-1));
  328.           $lines_to_keep_together_counter++;
  329.           if ($lines_to_keep_together_counter == $keep_together) { // if all grouped rows have been loaded, go to execute.
  330.             $complete_line = true;
  331.             $lines_to_keep_together_counter=0;
  332.             if ($collateSuffix != '' && @mysql_get_server_info() >= '4.1' && (!defined('IGNORE_DB_CHARSET') || (defined('IGNORE_DB_CHARSET') && IGNORE_DB_CHARSET != FALSE))) {
  333.               $newline = rtrim($newline, ';') . $collateSuffix . ';';
  334.               $collateSuffix = '';
  335.             }
  336.           } else {
  337.             $complete_line = false;
  338.           }
  339.         } //endif found ';'
  340.  
  341.         if ($complete_line) {
  342.           if ($debug==true) echo ((!$ignore_line) ? '<br /><strong>About to execute.</strong>': '<strong>Ignoring statement. This command WILL NOT be executed.</strong>').'<br />Debug info:<br />$ line='.$line.'<br />$ complete_line='.$complete_line.'<br>$ keep_together='.$keep_together.'<br />SQL='.$newline.'<br /><br />';
  343.           if (get_magic_quotes_runtime() > 0) $newline=stripslashes($newline);
  344.           $output = (trim(str_replace(';','',$newline)) != '' && !$ignore_line) ? $db->Execute($newline) : '';
  345.           $results++;
  346.           $string .= $newline.'<br />';
  347.           $return_output[]=$output;
  348.           if (zen_not_null($result) && !zen_check_exceptions($result, $line) ) $errors[]=$result;
  349.           // reset var's
  350.           $newline = '';
  351.           $keep_together=1;
  352.           $complete_line = false;
  353.           if ($ignore_line && !zen_check_exceptions($result, $line)) $ignored_count++;
  354.           $ignore_line=false;
  355.  
  356.           // show progress bar
  357.           global $zc_show_progress;
  358.           if ($zc_show_progress=='yes') {
  359.              $counter++;
  360.              if (($counter/5) == (int)($counter/5)) echo '~ ';
  361.              if ($counter>200) {
  362.                echo '<br /><br />';
  363.                $counter=0;
  364.              }
  365.              if (function_exists('ob_flush')) @ob_flush();
  366.              @flush();
  367.           }
  368.  
  369.         } //endif $complete_line
  370.  
  371.       } //endif ! # or -
  372.     } // end foreach $lines
  373.   return array('queries'=> $results, 'string'=>$string, 'output'=>$return_output, 'ignored'=>($ignored_count), 'errors'=>$errors);
  374.   } //end function
  375.  
  376.   function zen_db_prepare_input($string) {
  377.     if (is_string($string)) {
  378.       return trim(zen_sanitize_string(stripslashes($string)));
  379.     } elseif (is_array($string)) {
  380.       reset($string);
  381.       while (list($key, $value) = each($string)) {
  382.         $string[$key] = zen_db_prepare_input($value);
  383.       }
  384.       return $string;
  385.     } else {
  386.       return $string;
  387.     }
  388.   }
  389.  
  390.   function zen_sanitize_string($string) {
  391.     $string = preg_replace('/ +/', ' ', $string);
  392.     return preg_replace("/[<>]/", '_', $string);
  393.   }
  394.  
  395.   function zen_validate_email($email = "root@localhost.localdomain") {
  396.     $valid_address = true;
  397.     $user ="";
  398.     $domain="";
  399. // split the e-mail address into user and domain parts
  400. // need to update to trap for addresses in the format of "first@last"@someplace.com
  401. // this method will most likely break in that case
  402.   list( $user, $domain ) = explode( "@", $email );
  403.   $valid_ip_form = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';
  404.   $valid_email_pattern = '^[a-z0-9]+[a-z0-9_\.\'\-]*@[a-z0-9]+[a-z0-9\.\-]*\.(([a-z]{2,6})|([0-9]{1,3}))$';
  405.  $space_check = '[ ]';
  406.  
  407. // strip beginning and ending quotes, if and only if both present
  408.  if( (preg_match('/^["]/', $user) && preg_match('/["]$/', $user)) ){
  409.    $user = preg_replace ( '/^["]/', '', $user );
  410.    $user = preg_replace ( '/["]$/', '', $user );
  411.    $user = preg_replace ( '/'.$space_check.'/', '', $user ); //spaces in quoted addresses OK per RFC (?)
  412.    $email = $user."@".$domain; // contine with stripped quotes for remainder
  413.  }
  414.  
  415. // if e-mail domain part is an IP address, check each part for a value under 256
  416.  if (preg_match('/'.$valid_ip_form.'/', $domain)) {
  417.    $digit = explode( ".", $domain );
  418.    for($i=0; $i<4; $i++) {
  419.    if ($digit[$i] > 255) {
  420.      $valid_address = false;
  421.      return $valid_address;
  422.      exit;
  423.    }
  424. // stop crafty people from using internal IP addresses
  425.    if (($digit[0] == 192) || ($digit[0] == 10)) {
  426.      $valid_address = false;
  427.      return $valid_address;
  428.      exit;
  429.    }
  430.    }
  431.  }
  432.  
  433.  if (!preg_match('/'.$space_check.'/', $email)) { // trap for spaces in
  434.    if ( preg_match('/'.$valid_email_pattern.'/i', $email)) { // validate against valid e-mail patterns
  435.    $valid_address = true;
  436.    } else {
  437.    $valid_address = false;
  438.    return $valid_address;
  439.    exit;
  440.      }
  441.    }
  442.  
  443. // Verify e-mail has an associated MX and/or A record.
  444. // Need alternate method to deal with Verisign shenanigans and with Windows Servers
  445. //      if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
  446. //        $valid_address = false;
  447. //      }
  448.  
  449.    return $valid_address;
  450.  }
  451.  
  452.  function zen_encrypt_password($plain) {
  453.    $password = '';
  454.  
  455.    for ($i=0; $i<10; $i++) {
  456.      $password .= zen_rand();
  457.    }
  458.  
  459.    $salt = substr(md5($password), 0, 2);
  460.  
  461.    $password = md5($salt . $plain) . ':' . $salt;
  462.  
  463.    return $password;
  464.  }
  465.  
  466.  function zen_validate_password($plain, $encrypted) {
  467.    if (zen_not_null($plain) && zen_not_null($encrypted)) {
  468.      $stack = explode(':', $encrypted);
  469.      if (sizeof($stack) != 2) return false;
  470.      if (md5($stack[1] . $plain) == $stack[0]) {
  471.        return true;
  472.      }
  473.    }
  474.    return false;
  475.  }
  476.  
  477.  
  478.  function zen_rand($min = null, $max = null) {
  479.    static $seeded;
  480.  
  481.    if (!isset($seeded)) {
  482.      mt_srand((double)microtime()*1000000);
  483.      $seeded = true;
  484.    }
  485.  
  486.    if (isset($min) && isset($max)) {
  487.      if ($min >= $max) {
  488.        return $min;
  489.      } else {
  490.        return mt_rand($min, $max);
  491.      }
  492.    } else {
  493.      return mt_rand();
  494.    }
  495.  }
  496.  
  497.  function zen_read_config_value($value, $onlyMainFile = TRUE, $concatenate = FALSE) {
  498.    $files_array = array();
  499.    $retVal = $string='';
  500.    if (!$onlyMainFile) $files_array[] = '../includes/local/configure.php';
  501.    $files_array[] = '../includes/configure.php';
  502.  
  503. //    if (!$onlyMainFile && $za_dir = @dir('../includes/' . 'extra_configures')) {
  504. //      while ($zv_file = $za_dir->read()) {
  505. //        if (preg_match('~^[^\._].*\.php$~i', $zv_file) > 0) {
  506. //          //echo $zv_file.'<br>';
  507. //          $files_array[] = $zv_file;
  508. //        }
  509. //      }
  510. //      $za_dir->close(); unset($za_dir);
  511. //    }
  512.  
  513.    foreach ($files_array as $filename) {
  514.      if (!file_exists($filename)) continue;
  515.      //echo $filename . '!<br>';
  516.      $lines = file($filename);
  517.      foreach($lines as $line) { // read the configure.php file for specific variables
  518.        if (substr(trim($line),0,2) == '//') continue;
  519.         $def_string=array();
  520.         $def_string=explode("'",$line);
  521.         //define('CONSTANT','value');
  522.         //[1]=TABLE_CONSTANT
  523.         //[2]=,
  524.         //[3]=value
  525.         //[4]=);
  526.         //[5]=
  527.         if (isset($def_string[1]) && strtoupper($def_string[1]) == $value ) {
  528.           $string = $def_string[3];
  529.           continue;
  530.         }
  531.       } //end foreach $line
  532.       if ($retVal == '' || ($concatenate == TRUE && $string != '')) {
  533.         $retVal .= $string;
  534.       }
  535.     } //end foreach $filename
  536.    return $retVal;
  537.   }
  538.  
  539.   function zen_table_exists($tablename, $pre_install=false) {
  540.     global $db, $db_test;
  541.     if ($pre_install==true) {
  542.       $tables = $db_test->Execute("SHOW TABLES like '" . DB_PREFIX . $tablename . "'");
  543.     } else {
  544.       $tables = $db->Execute("SHOW TABLES like '" . DB_PREFIX . $tablename . "'");
  545.     }
  546.     if (ZC_UPG_DEBUG3==true) echo 'Table check ('.$tablename.') = '. $tables->RecordCount() .'<br>';
  547.     if ($tables->RecordCount() > 0) {
  548.       return true;
  549.     } else {
  550.       return false;
  551.     }
  552.   }
  553.  
  554.   function zen_check_database_privs($priv='',$table='',$show_privs=false) {
  555.     //bypass for now ... will attempt to use with modifications in a new release later
  556.     if ($show_privs==true) return 'Not Checked|||Not Checked';
  557.     return true;
  558.     // end bypass
  559.     global $zdb_server, $zdb_user, $zdb_name;
  560.     if (!zen_not_null($zdb_server)) $zdb_server = zen_read_config_value('DB_SERVER', FALSE);
  561.     if (!zen_not_null($zdb_user)) $zdb_user     = zen_read_config_value('DB_SERVER_USERNAME', FALSE);
  562.     if (!zen_not_null($zdb_name)) $zdb_name     = zen_read_config_value('DB_DATABASE', FALSE);
  563.     if (isset($_GET['nogrants']) || isset($_POST['nogrants']) ) return true; // bypass if flag set
  564.     //Display permissions, or check for suitable permissions to carry out a particular task
  565.       //possible outputs:
  566.       //GRANT ALL PRIVILEGES ON *.* TO 'xyz'@'localhost' WITH GRANT OPTION
  567.       //GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER ON *.* TO 'xyz'@'localhost' IDENTIFIED BY PASSWORD '2344'
  568.       //GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `db1`.* TO 'xyz'@'localhost'
  569.       //GRANT SELECT (id) ON db1.tablename TO 'xyz'@'localhost
  570.     global $db;
  571.     global $db_test;
  572.     $granted_privs_list='';
  573.     if (ZC_UPG_DEBUG3==true) echo '<br />Checking for priv: ['.(zen_not_null($priv) ? $priv : 'none specified').']<br />';
  574.     if (!defined('DB_SERVER'))          define('DB_SERVER',$zdb_server);
  575.     if (!defined('DB_SERVER_USERNAME')) define('DB_SERVER_USERNAME',$zdb_user);
  576.     if (!defined('DB_DATABASE'))        define('DB_DATABASE',$zdb_name);
  577.     $user = DB_SERVER_USERNAME."@".DB_SERVER;
  578.     if ($user == 'DB_SERVER_USERNAME@DB_SERVER' || DB_DATABASE=='DB_DATABASE') return true; // bypass if constants not set properly
  579.     $sql = "show grants for ".$user;
  580.     if (ZC_UPG_DEBUG3==true) echo $sql.'<br />';
  581.     if (is_object($db)) {
  582.       $result = $db->Execute($sql);
  583.     } elseif (is_object($db_test)) {
  584.       $result = $db_test->Execute($sql);
  585.     }
  586.     while (!$result->EOF) {
  587.       if (ZC_UPG_DEBUG3==true) echo $result->fields['Grants for '.$user].'<br />';
  588.       $grant_syntax = $result->fields['Grants for '.$user] . ' ';
  589.       $granted_privs = str_replace('GRANT ','',$grant_syntax); // remove "GRANT" keyword
  590.       $granted_privs = substr($granted_privs,0,strpos($granted_privs,' TO ')); //remove anything after the "TO" keyword
  591.       $granted_db = str_replace(array('`','\\'),'',substr($granted_privs,strpos($granted_privs,' ON ')+4) ); //remove backquote and find "ON" string
  592.       if (ZC_UPG_DEBUG3==true) echo 'privs_list = '.$granted_privs.'<br />';
  593.       if (ZC_UPG_DEBUG3==true) echo 'granted_db = '.$granted_db.'<br />';
  594.       $db_priv_ok += ($granted_db == '*.*' || $granted_db==DB_DATABASE.'.*' || $granted_db==DB_DATABASE.'.'.$table) ? true : false;
  595.       if (ZC_UPG_DEBUG3==true) echo 'db-priv-ok='.$db_priv_ok.'<br />';
  596.  
  597.       if ($db_priv_ok) {  // if the privs list pertains to the current database, or is *.*, carry on
  598.         $granted_privs = substr($granted_privs,0,strpos($granted_privs,' ON ')); //remove anything after the "ON" keyword
  599.         $granted_privs_list .= ($granted_privs_list=='') ? $granted_privs : ', '.$granted_privs;
  600.  
  601.         $specific_priv_found = (zen_not_null($priv) && substr_count($granted_privs,$priv)==1);
  602.         if (ZC_UPG_DEBUG3==true) echo 'specific priv['.$priv.'] found ='.$specific_priv_found.'<br />';
  603.  
  604.         if (ZC_UPG_DEBUG3==true) echo 'spec+db='.($specific_priv_found && $db_priv_ok == true).' ||| ';
  605.         if (ZC_UPG_DEBUG3==true) echo 'all+db='.($granted_privs == 'ALL PRIVILEGES' && $db_priv_ok==true).'<br /><br />';
  606.  
  607.         if (($specific_priv_found && $db_priv_ok == true) || ($granted_privs == 'ALL PRIVILEGES' && $db_priv_ok==true)) {
  608.           return true; // privs found
  609.         }
  610.       } // endif $db_priv_ok
  611.       $result->MoveNext();
  612.     }
  613.     if ($show_privs) {
  614.       if (ZC_UPG_DEBUG3==true) echo 'LIST OF PRIVS='.$granted_privs_list.'<br />';
  615.       return $db_priv_ok . '|||'. $granted_privs_list;
  616.     } else {
  617.     return false; // if not found, return false
  618.     }
  619.   }
  620.  
  621.   function zen_drop_index_command($param) {
  622.     if (!$checkprivs = zen_check_database_privs('INDEX')) return sprintf(REASON_NO_PRIVILEGES,'INDEX');
  623.     //this is only slightly different from the ALTER TABLE DROP INDEX command
  624.     global $db;
  625.     if (!zen_not_null($param)) return "Empty SQL Statement";
  626.     $index = $param[2];
  627.     $sql = "show index from " . DB_PREFIX . $param[4];
  628.     $result = $db->Execute($sql);
  629.     while (!$result->EOF) {
  630.       if (ZC_UPG_DEBUG3==true) echo $result->fields['Key_name'].'<br />';
  631.       if  ($result->fields['Key_name'] == $index) {
  632. //        if (!$checkprivs = zen_check_database_privs('INDEX')) return sprintf(REASON_NO_PRIVILEGES,'INDEX');
  633.         return; // if we get here, the index exists, and we have index privileges, so return with no error
  634.       }
  635.       $result->MoveNext();
  636.     }
  637.     // if we get here, then the index didn't exist
  638.     return sprintf(REASON_INDEX_DOESNT_EXIST_TO_DROP,$index,$param[4]);
  639.   }
  640.  
  641.   function zen_create_index_command($param) {
  642.     //this is only slightly different from the ALTER TABLE CREATE INDEX command
  643.     if (!$checkprivs = zen_check_database_privs('INDEX')) return sprintf(REASON_NO_PRIVILEGES,'INDEX');
  644.     global $db;
  645.     if (!zen_not_null($param)) return "Empty SQL Statement";
  646.     $index = (strtoupper($param[1])=='INDEX') ? $param[2] : $param[3];
  647.     if (in_array('USING',$param)) return 'USING parameter found. Cannot validate syntax. Please run manually in phpMyAdmin.';
  648.     $table = (strtoupper($param[2])=='INDEX' && strtoupper($param[4])=='ON') ? $param[5] : $param[4];
  649.     $sql = "show index from " . DB_PREFIX . $table;
  650.     $result = $db->Execute($sql);
  651.     while (!$result->EOF) {
  652.       if (ZC_UPG_DEBUG3==true) echo $result->fields['Key_name'].'<br />';
  653.       if (strtoupper($result->fields['Key_name']) == strtoupper($index)) {
  654.         return sprintf(REASON_INDEX_ALREADY_EXISTS,$index,$table);
  655.       }
  656.       $result->MoveNext();
  657.     }
  658. /*
  659.  * @TODO: verify that individual columns exist, by parsing the index_col_name parameters list
  660.  *        Structure is (colname(len)),
  661.  *                  or (colname),
  662.  */
  663.   }
  664.  
  665.   function zen_check_alter_command($param) {
  666.     global $db;
  667.     if (!zen_not_null($param)) return "Empty SQL Statement";
  668.     if (!$checkprivs = zen_check_database_privs('ALTER')) return sprintf(REASON_NO_PRIVILEGES,DB_SERVER_USERNAME, DB_SERVER, 'ALTER');
  669.     if (!$tbl_exists = zen_table_exists($param[2])) return sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' CHECK PREFIXES!';
  670.     switch (strtoupper($param[3])) {
  671.       case ("ADD"):
  672.         if (strtoupper($param[4]) == 'INDEX') {
  673.           // check that the index to be added doesn't already exist
  674.           $index = $param[5];
  675.           $sql = "show index from " . DB_PREFIX . $param[2];
  676.           $result = $db->Execute($sql);
  677.           while (!$result->EOF) {
  678.             if (ZC_UPG_DEBUG3==true) echo 'KEY: '.$result->fields['Key_name'].'<br />';
  679.             if  ($result->fields['Key_name'] == $index) {
  680.               return sprintf(REASON_INDEX_ALREADY_EXISTS,$index,$param[2]);
  681.             }
  682.             $result->MoveNext();
  683.           }
  684.         } elseif (strtoupper($param[4])=='PRIMARY') {
  685.           // check that the primary key to be added doesn't exist
  686.           if ($param[5] != 'KEY') return;
  687.           $sql = "show index from " . DB_PREFIX . $param[2];
  688.           $result = $db->Execute($sql);
  689.           while (!$result->EOF) {
  690.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Key_name'].'<br />';
  691.             if  ($result->fields['Key_name'] == 'PRIMARY') {
  692.               return sprintf(REASON_PRIMARY_KEY_ALREADY_EXISTS,$param[2]);
  693.             }
  694.             $result->MoveNext();
  695.           }
  696.  
  697.         } elseif (!in_array(strtoupper($param[4]),array('CONSTRAINT','UNIQUE','PRIMARY','FULLTEXT','FOREIGN','SPATIAL') ) ) {
  698.         // check that the column to be added does not exist
  699.           $colname = ($param[4]=='COLUMN') ? $param[5] : $param[4];
  700.           $sql = "show fields from " . DB_PREFIX . $param[2];
  701.           $result = $db->Execute($sql);
  702.           while (!$result->EOF) {
  703.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Field'].'<br />';
  704.             if  ($result->fields['Field'] == $colname) {
  705.               return sprintf(REASON_COLUMN_ALREADY_EXISTS,$colname);
  706.             }
  707.             $result->MoveNext();
  708.           }
  709.  
  710.         } elseif (strtoupper($param[5])=='AFTER') {
  711.           // check that the requested "after" field actually exists
  712.           $colname = ($param[6]=='COLUMN') ? $param[7] : $param[6];
  713.           $sql = "show fields from " . DB_PREFIX . $param[2];
  714.           $result = $db->Execute($sql);
  715.           while (!$result->EOF) {
  716.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Field'].'<br />';
  717.             if  ($result->fields['Field'] == $colname) {
  718.               return; // exists, so return with no error
  719.             }
  720.             $result->MoveNext();
  721.           }
  722.  
  723.         } elseif (strtoupper($param[6])=='AFTER') {
  724.           // check that the requested "after" field actually exists
  725.           $colname = ($param[7]=='COLUMN') ? $param[8] : $param[7];
  726.           $sql = "show fields from " . DB_PREFIX . $param[2];
  727.           $result = $db->Execute($sql);
  728.           while (!$result->EOF) {
  729.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Field'].'<br />';
  730.             if  ($result->fields['Field'] == $colname) {
  731.               return; // exists, so return with no error
  732.             }
  733.             $result->MoveNext();
  734.           }
  735. /*
  736.  * @TODO -- add check for FIRST parameter, to check that the FIRST colname specified actually exists
  737.  */
  738.         }
  739.         break;
  740.       case ("DROP"):
  741.         if (strtoupper($param[4]) == 'INDEX') {
  742.           // check that the index to be dropped exists
  743.           $index = $param[5];
  744.           $sql = "show index from " . DB_PREFIX . $param[2];
  745.           $result = $db->Execute($sql);
  746.           while (!$result->EOF) {
  747.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Key_name'].'<br />';
  748.             if  ($result->fields['Key_name'] == $index) {
  749.               return; // exists, so return with no error
  750.             }
  751.             $result->MoveNext();
  752.           }
  753.           // if we get here, then the index didn't exist
  754.           return sprintf(REASON_INDEX_DOESNT_EXIST_TO_DROP,$index,$param[2]);
  755.  
  756.         } elseif (strtoupper($param[4])=='PRIMARY') {
  757.           // check that the primary key to be dropped exists
  758.           if ($param[5] != 'KEY') return;
  759.           $sql = "show index from " . DB_PREFIX . $param[2];
  760.           $result = $db->Execute($sql);
  761.           while (!$result->EOF) {
  762.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Key_name'].'<br />';
  763.             if  ($result->fields['Key_name'] == 'PRIMARY') {
  764.               return; // exists, so return with no error
  765.             }
  766.             $result->MoveNext();
  767.           }
  768.           // if we get here, then the primary key didn't exist
  769.           return sprintf(REASON_PRIMARY_KEY_DOESNT_EXIST_TO_DROP,$param[2]);
  770.  
  771.         } elseif (!in_array(strtoupper($param[4]),array('CONSTRAINT','UNIQUE','PRIMARY','FULLTEXT','FOREIGN','SPATIAL'))) {
  772.           // check that the column to be dropped exists
  773.           $colname = ($param[4]=='COLUMN') ? $param[5] : $param[4];
  774.           $sql = "show fields from " . DB_PREFIX . $param[2];
  775.           $result = $db->Execute($sql);
  776.           while (!$result->EOF) {
  777.             if (ZC_UPG_DEBUG3==true) echo $result->fields['Field'].'<br />';
  778.             if  ($result->fields['Field'] == $colname) {
  779.               return; // exists, so return with no error
  780.             }
  781.             $result->MoveNext();
  782.           }
  783.           // if we get here, then the column didn't exist
  784.           return sprintf(REASON_COLUMN_DOESNT_EXIST_TO_DROP,$colname);
  785.         }//endif 'DROP'
  786.         break;
  787.       case ("ALTER"):
  788.       case ("MODIFY"):
  789.       case ("CHANGE"):
  790.         // just check that the column to be changed 'exists'
  791.         $colname = ($param[4]=='COLUMN') ? $param[5] : $param[4];
  792.         $sql = "show fields from " . DB_PREFIX . $param[2];
  793.         $result = $db->Execute($sql);
  794.         while (!$result->EOF) {
  795.           if (ZC_UPG_DEBUG3==true) echo 'Field: ' . $result->fields['Field'].'<br />';
  796.           if  ($result->fields['Field'] == $colname) {
  797.             if (ZC_UPG_DEBUG3==true) echo '**FOUND**<br />';
  798.             return; // exists, so return with no error
  799.           }
  800.           $result->MoveNext();
  801.         }
  802.         if (ZC_UPG_DEBUG3==true) echo '******NOT FOUND (' . $colname . ') ******<br />';
  803.         // if we get here, then the column didn't exist
  804.         return sprintf(REASON_COLUMN_DOESNT_EXIST_TO_CHANGE,$colname);
  805.         break;
  806.       default:
  807.         // if we get here, then we're processing an ALTER command other than what we're checking for, so let it be processed.
  808.         return;
  809.         break;
  810.     } //end switch
  811.   }
  812.  
  813.   function zen_check_config_key($line) {
  814.     global $db;
  815.     $values=array();
  816.     $values=explode("'",$line);
  817.      //INSERT INTO configuration blah blah blah VALUES ('title','key', blah blah blah);
  818.      //[0]=INSERT INTO.....
  819.      //[1]=title
  820.      //[2]=,
  821.      //[3]=key
  822.      //[4]=blah blah
  823.     $title = $values[1];
  824.     $key  =  $values[3];
  825.     $sql = "select configuration_title from " . DB_PREFIX . "configuration where configuration_key='".$key."'";
  826.     $result = $db->Execute($sql);
  827.     if ($result->RecordCount() >0 ) return sprintf(REASON_CONFIG_KEY_ALREADY_EXISTS,$key);
  828.   }
  829.  
  830.   function zen_check_product_type_layout_key($line) {
  831.     global $db;
  832.     $values=array();
  833.     $values=explode("'",$line);
  834.     $title = $values[1];
  835.     $key  =  $values[3];
  836.     $sql = "select configuration_title from " . DB_PREFIX . "product_type_layout where configuration_key='".$key."'";
  837.     $result = $db->Execute($sql);
  838.     if ($result->RecordCount() >0 ) return sprintf(REASON_PRODUCT_TYPE_LAYOUT_KEY_ALREADY_EXISTS,$key);
  839.   }
  840.  
  841.   function zen_check_cfggroup_key($line) {
  842.     global $db;
  843.     $values=array();
  844.     $values=explode("'",$line);
  845.     $id = $values[1];
  846.     $title  =  $values[3];
  847.     $sql = "select configuration_group_title from " . DB_PREFIX . "configuration_group where configuration_group_title='".$title."'";
  848.     $result = $db->Execute($sql);
  849.     if ($result->RecordCount() >0 ) return sprintf(REASON_CONFIGURATION_GROUP_KEY_ALREADY_EXISTS,$title);
  850.     $sql = "select configuration_group_title from " . DB_PREFIX . "configuration_group where configuration_group_id='".$id."'";
  851.     $result = $db->Execute($sql);
  852.     if ($result->RecordCount() >0 ) return sprintf(REASON_CONFIGURATION_GROUP_ID_ALREADY_EXISTS,$id);
  853.   }
  854.  
  855.   function zen_write_to_upgrade_exceptions_table($line, $reason, $sql_file) {
  856.     global $db;
  857.     zen_create_exceptions_table();
  858.     $sql="INSERT INTO " . DB_PREFIX . TABLE_UPGRADE_EXCEPTIONS . " VALUES (0,:file:, :reason:, now(), :line:)";
  859.     $sql = $db->bindVars($sql, ':file:', $sql_file, 'string');
  860.     $sql = $db->bindVars($sql, ':reason:', $reason, 'string');
  861.     $sql = $db->bindVars($sql, ':line:', $line, 'string');
  862.     if (ZC_UPG_DEBUG3==true) echo '<br />sql='.$sql.'<br />';
  863.     $result = $db->Execute($sql);
  864.     return $result;
  865.   }
  866.  
  867.   function zen_purge_exceptions_table() {
  868.     global $db;
  869.     zen_create_exceptions_table();
  870.     $result = $db->Execute("TRUNCATE TABLE " . DB_PREFIX . TABLE_UPGRADE_EXCEPTIONS );
  871.     return $result;
  872.   }
  873.  
  874.   function zen_create_exceptions_table() {
  875.     global $db;
  876.     if (!zen_table_exists(TABLE_UPGRADE_EXCEPTIONS)) {
  877.       $result = $db->Execute("CREATE TABLE " . DB_PREFIX . TABLE_UPGRADE_EXCEPTIONS ." (
  878.            upgrade_exception_id smallint(5) NOT NULL auto_increment,
  879.            sql_file varchar(50) default NULL,
  880.            reason varchar(200) default NULL,
  881.            errordate datetime default '0001-01-01 00:00:00',
  882.            sqlstatement text, PRIMARY KEY  (upgrade_exception_id)
  883.          )");
  884.     return $result;
  885.     }
  886.   }
  887.  
  888.   function zen_check_exceptions($result, $line) {
  889.     // note: table-prefixes are ignored here, since they are not added if this is an exception
  890.     //echo '<br /><strong>RESULT_CODE: </strong>' . $result . '<br /><strong>LINE:</strong>' . $line;
  891.     if (strstr($result,'EZ-Pages Settings') && strstr(strtolower($line), 'insert into configuration_group')) return true;
  892.     if (strstr($result,'DEFINE_SITE_MAP_STATUS') && strstr(strtolower($line), 'insert into configuration')) return true;
  893.     //echo '<br /><strong>NO EXCEPTIONS </strong>TO IGNORE<br />';
  894.   }
  895.  
  896.   function zcInstallAddSID($connection = '') {
  897.     global $request_type, $session_started, $http_domain, $https_domain;
  898.     $sid = '';
  899.     if ($connection == '') $connection = $request_type;
  900.     // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
  901.     if ($session_started == true) {
  902.       if (defined('SID') && zen_not_null(SID)) {
  903.         $sid = SID;
  904.       } elseif ( ($request_type == 'NONSSL' && $connection == 'SSL') || ($request_type == 'SSL' && $connection == 'NONSSL') ) {
  905.         if ($http_domain != $https_domain) {
  906.           $sid = zen_session_name() . '=' . zen_session_id();
  907.         }
  908.       }
  909.     }
  910.     return ($sid == '') ? '' : '&' . zen_output_string($sid);
  911.   }
  912.  
  913. ////
  914.   function zen_create_random_value($length, $type = 'mixed') {
  915.     if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;
  916.  
  917.     $rand_value = '';
  918.     while (strlen($rand_value) < $length) {
  919.       if ($type == 'digits') {
  920.         $char = zen_rand(0,9);
  921.       } else {
  922.         $char = chr(zen_rand(0,255));
  923.       }
  924.       if ($type == 'mixed') {
  925.         if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
  926.       } elseif ($type == 'chars') {
  927.         if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
  928.       } elseif ($type == 'digits') {
  929.         if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;
  930.       }
  931.     }
  932.  
  933.     return $rand_value;
  934.   }
  935.  


cron