Location: PHPKode > projects > PhpProjectMaster > www/php/site_value.php
<?php
/* 
 Site Settings Data Management
 (c) 2004-2007 by "Oleg Savchuk" <hide@address.com>

 part of phpProjectMaster project
 http://phpprojmaster.sourceforge.net

 The contents of this file are subject to the GNU GENERAL PUBLIC LICENSE
 http://www.gnu.org/copyleft/gpl.html

*/

 session_start();
require_once "../inc/sitelib.php";
require_once "../inc/site_value.php";
require_once "../inc/form_utils.php";
require_once "../inc/user.php";

 check_access(100);

 global_init();

$CGI_ACTIONS=array(
  ''           => 'show_item_list',
  'AddNew'     => 'show_add_item',
  'Edit'       => 'show_one_item',
  'SaveRec'    => 'save_one_item',
  'DelRec'     => 'delete_item',
);

###########

 $SYS=$_REQUEST["sys"];
 if (!$SYS) {
    echo "No sys set";
    exit;
 }

 go_action();

exit;

###########################################################################
# show item list
#


####################
function show_item_list(){
 global $rowcolor, $SYS;

 $cdr=array();
 $sql="select * from site_value
 where iname LIKE ".db_quote($SYS.".%")."
   and is_user_edit=1
 order by iname";
 $sth=db_query($sql);
 while($hr=mysql_fetch_assoc($sth)){
    $rowcolor=array($rowcolor[1],$rowcolor[0]);

    $cdr[]=array_merge($hr, array(
      'bgcolor' => $rowcolor[0],
      'sys'     => $SYS,
      'iname'   => cut_prefix($hr['iname'], $SYS),
    ));
 }

 $ps=array(
   'sys'  => $SYS,
   'item_datarow' => $cdr,
 );
 $ps=array_merge($ps, get_userinfo());
 parse_page("/admin/site_value/list", $GLOBALS['PAGE_TPL_ADMIN'], $ps);
}


####################
function show_add_item(){
 global $SYS;

 $hITEM=$_REQUEST["item"];
# $hITEM["sendnotify"]=1 if !$hITEM; #initially check sendnotify

 $ps=array_merge($hITEM, array(
   'sys'  => $SYS,
 ));
 $ps=array_merge($ps, get_userinfo());
 parse_page("/admin/site_value/add", $GLOBALS['PAGE_TPL_ADMIN'], $ps);
}

####################
# $forceform=$_[0];  #if 1 - redisplay values from FORM, not DB
function show_one_item($forceform=0){
 global $SYS;

 $item_id=$_REQUEST["id"]+0;
 $hITEM;
 $hITEMDB=get_site_value_rec($item_id);

 if ($forceform){
    $hITEM=array_merge($hITEMDB, $_REQUEST["item"]);
    $hITEM["sv_id"]=$item_id;
 } else {
    $hITEM=$hITEMDB;
 }
 $hITEM['iname']=cut_prefix($hITEM['iname'], $SYS);

 $ps=array_merge($hITEM, array(
   'sys'  => $SYS,
 ));
 $ps=array_merge($ps, get_userinfo());
 parse_page("/admin/site_value/edit", $GLOBALS['PAGE_TPL_ADMIN'], $ps);
}

#################### save user info
function save_one_item(){
 global $SYS;
 $item_id=$_REQUEST["id"];

 if (validate_item($item_id, $_REQUEST["item"])){
    $IFORM=$_REQUEST["item"];

    if ($item_id){  #id exists - update record

       $sql="update site_value set ".get_sqlupdate_set($IFORM).", upd_time=now() where sv_id=$item_id";
       logger($sql);
       db_query($sql);

       $GLOBALS['green_msg']="Record has been modified";
    } else {     #id not exits - insert record
       $IFORM['iname']=$SYS.".".$IFORM['iname'];
       $IFORM['is_user_edit']=1;

       $sql="insert into site_value ".get_sqlinsert_set($IFORM,', upd_time',', now()');
       logger($sql);
       $sth=db_query($sql);
       $item_id=get_identity();

       $GLOBALS['green_msg']="New Record has been added.";

       do_redirect("/php/site_value.php?sys=$SYS&green_msg=".escape_str($GLOBALS['green_msg'])."&err_msg=".escape_str($GLOBALS['err_msg']));
       return;
    }
    $_REQUEST["id"]=$item_id;

    show_one_item();
 } else {
    if ($item_id){
       show_one_item(1);
    } else {
       show_add_item();
    }
 }
}


################# Validate user form values in FORM{item}
function validate_item($item_id, $IFORM){
 global $SYS;

 $item_id+=0;
 $REQFLD=array(
'ivalue'        =>array('Value'),
);

 if (!$item_id) $REQFLD['iname']=array('Name');

 #VALIDATE REQUIRED FIELDS
 if (!$GLOBALS['err_msg'])  $GLOBALS['err_msg']=validate_form($IFORM, $REQFLD) ;

 #VALIDATE if Email unique
 if (!$item_id && !$GLOBALS['err_msg'] && is_dbrecord_exists2('site_value','iname',$SYS.".".$IFORM["iname"], " and sv_id<>$item_id")){
    $GLOBALS['err_msg']="Such Record already exists. Please, select another name.";
 }

 if ($GLOBALS['err_msg']) return 0;
 return 1;
}

?>
Return current item: PhpProjectMaster