Location: PHPKode > projects > Esvon Personals > esvon-personals/upgrades/v3_to_v4/upgrade313-314.php
<?php

// File to upgrade Esvon Classifieds from 3.0.790 to 3.0.793
// After use this, you can delete it

//*********************************************

define('DB_UPGRADE', 1);

if(!defined('SITE_PATH')){
  if(!file_exists('./inc/application.php')) die("File Not Found: application.php");
  require_once './inc/application.php';
}
 
mysql_query("ALTER TABLE ".TBL_PAY_PLAN." DROP exp_date_modify");

$res = $db->query('SELECT id,hw_pay_plan,UNIX_TIMESTAMP(exp_date) AS exp_date FROM '.TBL_USER);
while($v = mysql_fetch_assoc($res)){
  list($pp_id,$pp_ts) = hwGetBasePlanFromStr($v['hw_pay_plan']);
  if($v['exp_date'] && $v['exp_date'] > $pp_ts){
    $hw_pay_plan = str_replace("[$pp_id-$pp_ts]","[$pp_id-".$v['exp_date']."]",$v['hw_pay_plan']);
    $db->query('UPDATE '.TBL_USER." SET hw_pay_plan='$hw_pay_plan' WHERE id='$v[id]'");
  }
}

$res = $db->query('SELECT link_id AS id,hw_pay_plan,UNIX_TIMESTAMP(exp_date) AS exp_date FROM '.TBL_AD);
while($v = mysql_fetch_assoc($res)){
  list($pp_id,$pp_ts) = hwGetBasePlanFromStr($v['hw_pay_plan']);
  if($v['exp_date'] && $v['exp_date'] > $pp_ts){
    $hw_pay_plan = str_replace("[$pp_id-$pp_ts]","[$pp_id-".$v['exp_date']."]",$v['hw_pay_plan']);
    $hw_pay_plan = Ex_Opts_Update_Exp_Date($hw_pay_plan);
    $db->query('UPDATE '.TBL_AD." SET hw_pay_plan='$hw_pay_plan' WHERE link_id='$v[id]'");
  }
}

if(hwModGetState('Multi_Lang')){
  mysql_query("ALTER TABLE ".hwModTable('Multi_Lang','category')." ADD descr text NOT NULL");
  mysql_query("ALTER TABLE ".hwModTable('Multi_Lang','data')." CHANGE id id varchar(60) NOT NULL");
  mysql_query("ALTER TABLE ".hwModTable('Multi_Lang','data')." CHANGE phrase phrase text NOT NULL");
}

mysql_query('CREATE TABLE '.TBL_FIELD.' (
   idx mediumint(8) unsigned NOT NULL auto_increment,
   fset varchar(30) NOT NULL,
   weight smallint(5) unsigned NOT NULL,
   id varchar(40) NOT NULL,
   db_f varchar(40) NOT NULL,
   active tinyint(3) NOT NULL,
   required tinyint(3) NOT NULL,
   search_k tinyint(3) NOT NULL,
   editable char(1) NOT NULL,
   search varchar(255) NOT NULL,
   title varchar(255) NOT NULL,
   value varchar(255) NOT NULL,
   type varchar(255) NOT NULL,
   extra text NOT NULL,
   size varchar(255) NOT NULL,
   min varchar(255) NOT NULL,
   max varchar(255) NOT NULL,
   input varchar(255) NOT NULL,
   chars varchar(255) NOT NULL, 
   err_msg text NOT NULL,
   txt text NOT NULL,
   PRIMARY KEY (idx),
   UNIQUE(fset, id),
   UNIQUE(fset, db_f))');


mysql_query('CREATE TABLE '.TBL_FS.' (
   id varchar(30) NOT NULL,
   descr text NOT NULL,
   PRIMARY KEY (id))');

include_once SITE_PATH.'inc/class.fs_imp.php';

$a_v = hwFieldSetGetAll_Old();
if($a_v) foreach($a_v as $fs){
  $f = TPL_PATH.FS_DIR.'/'.$fs.'/fields.txt';
  $amt = $db->one_data('SELECT count(*) FROM '.TBL_FIELD.' WHERE fset="'.$fs.'"');
  if(!$amt && is_file($f)){
    $o_fs = new HawkFS($f, $fs);
    $o_fs->ImportFromFile('rename');
  }
}

// Other Fields Import

$a_v = array(
  FS_CH1.'user_fields'.FS_CH2 => TPL_PATH.'/ufields.txt',
);

foreach($a_v as $fs=>$f){
  $amt = $db->one_data('SELECT count(*) FROM '.TBL_FIELD.' WHERE fset="'.$fs.'"');
  if(!$amt && is_file($f)){
    $o_fs = new HawkFS($f, $fs);
    $o_fs->ImportFromFile('rename');
  }
}


mysql_query('DELETE FROM '.TBL_FIELD.' WHERE fset="{user_fields}" 
AND db_f IN ("exp_date","en_exp_modify","free_ad_used","regdate","reg_ip","hw_ads_max","disabled","lastlogin","lastlogin_ip","email","username","pwd")');

mysql_query('DELETE FROM '.TBL_FIELD.' WHERE fset<>"{user_fields}" 
AND db_f IN ("hw_weight","exp_date","hits","num_votes","rating")');

mysql_query("INSERT INTO ".TBL_FIELD." (fset, weight, id, db_f, editable, active, required, search_k, search, title, value, type, extra, size, min, max, input, chars, err_msg, txt) VALUES

('{user_fields}', 1, 'email', 'email', 'R', 1, 1, 0, '', 'E-mail', '', 'text', '', '20', '', '', 'email', '', '', ''),
('{user_fields}', 2, 'username', 'username', '', 1, 1, 0, '', 'Username', '', 'text', '', '20', '3', '25', 'alpha', '', '', ''),
('{user_fields}', 3, 'pwd', 'pwd', '', 1, 1, 0, '', 'Password', '', 'password', '', '20', '3', '20', '', '', '', ''),
('{user_fields}', 2001, 'exp_date', 'exp_date', '', 0, 0, 0, '', 'Account Expires', '', 'datetime', '2004,2037', '', '', '', '', '', '', ''),
('{user_fields}', 2002, 'en_exp_modify', 'en_exp_modify', '', 0, 0, 0, '', 'User can update Ads Exp. Date ?', '', 'checkbox', '1', '', '', '', '', '', '', ''),
('{user_fields}', 2003, 'free_ad_used', 'free_ad_used', '', 0, 0, 0, '', 'Free Ad possibility used ?', '', 'checkbox', '1', '', '', '', '', '', '', ''),
('{user_fields}', 2004, 'regdate', 'regdate', '', 0, 0, 0, '', 'Account Created', 'NOW', 'datetime', '2003,2010', '', '', '', '', '', '', ''),
('{user_fields}', 2010, 'reg_ip', 'reg_ip', '', 0, 0, 0, '', 'Registration IP', '', 'hidden', '', '', '', '', '', '', '', ''),
('{user_fields}', 2006, 'hw_ads_max', 'hw_ads_max', '', 0, 0, 0, '', 'Max {items} allowed', '0', 'text', '', '5', '', '5', 'digit', '', '', 'Set 0 to use global value from \"General Setup\"'),
('{user_fields}', 2007, 'disabled', 'disabled', '', 0, 0, 0, '', 'Disable account login?', '', 'checkbox', '1', '', '', '', '', '', '', ''),
('{user_fields}', 2008, 'lastlogin', 'lastlogin', '', 0, 0, 0, '', 'Last Login Date', '', 'hidden', '', '', '', '', '', '', '', ''),
('{user_fields}', 2010, 'lastlogin_ip', 'lastlogin_ip', '', 0, 0, 0, '', 'Last Login IP', '', 'hidden', '', '', '', '', '', '', '', '')
");

echo 'Esvon Classifieds Tables Updated, Ok.. ('.basename(__FILE__).')';


// funcs

function Ex_Opts_Update_Exp_Date($hw_pay_plan){

$a_v = hwPayOptsToArr($hw_pay_plan);
if($a_v) foreach($a_v as $z){
  if(!isset($z['VAL'])) continue;
  $hw_pay_plan = str_replace("[$z[ID]-$z[DT]-$z[VAL]]","[$z[ID]-".($z['DT']+EX_OPT_EXP*86400)."-$z[VAL]]",$hw_pay_plan);
}
return $hw_pay_plan;
}

function hwFieldSetGetAll_Old(){
  $a_f = array();
  $dir = TPL_PATH.FS_DIR.'/';
  if(is_dir($dir)){
    $hd = opendir($dir);
    while($f = readdir($hd)){
      if($f[0]=='.') continue;
      if(is_dir($dir.$f) && strpos($f,' ')===false) $a_f[]=$f;
    }
    closedir($hd);
  }
  sort($a_f);
  return $a_f;
}

?>
Return current item: Esvon Personals