getProperty('user_gid'); //}}} //}}} //{{{ --- MAIN CODE --- switch($_GET['action']) { case 'add' : //{{{ create QF and smarty objects $form = new HTML_Quickform('NewForm','POST','groups.php?action=add'); $smarty_obj = new SmartyQFWrapper('group_form.tpl'); //}}} if ('Add a new group'!=$_POST['btnAction']) { $smarty_obj->assign('access_denied','true'); break; } else { $smarty_obj->assign('action',$_POST['btnAction']); } //{{{ create elements $form->addElement('header','hdrTop','Add New Group'); $form->addElement('text','txtGroupName','Group Name: '); $form->addElement('submit','btnAddEdit','Add a new group'); //}}} //{{{ create rules $form->addRule('txtGroupName','*required','required'); //}}} break; case 'edit' : //{{{ create QF and smarty objects $form = new HTML_Quickform('NewForm','POST','groups.php?action=edit'); $smarty_obj = new SmartyQFWrapper('group_form.tpl'); //}}} if ('Edit group'!=$_POST['btnAction']) { $smarty_obj->assign('access_denied','true'); break; } else { $smarty_obj->assign('action',$_POST['btnAction']); } $group_id = $_POST['user_group_id']; $smarty_obj->assign('user_group_id',$group_id); //{{{ create elements $form->addElement('header','hdrTop','Edit Existing Group'); $form->addElement('text','txtGroupName','Group Name: '); $form->addElement('submit','btnAddEdit','Edit group'); //}}} //{{{ create rules $form->addRule('required','txtGroupName','*required'); //}}} //{{{ assign defaults from db $group_query="SELECT `user_group_name` FROM `user_groups` WHERE `user_group_id`='$group_id'"; $group_res=$db->query($group_query); if (handleError($group_res)) { $group_res->fetchInto($group_row); } $defaults=array('txtGroupName'=>$group_row['user_group_name']); $form->setDefaults($defaults); //}}} break; case 'delete' : //{{{ create QF and smarty objects $form = new HTML_Quickform('NewForm','POST','groups.php?action=delete'); $smarty_obj = new SmartyQFWrapper('group_delete.tpl'); //}}} if (('Delete group'!=$_POST['btnAction'])&&('Confirm Deletion!'!=$_POST['btnDelete'])&&('Delete Group!'!=$_POST['btnDelete'])) { $smarty_obj->assign('access_denied','true'); break; } else { $smarty_obj->assign('action',$_POST['btnAction']); $smarty_obj->assign('user_group_name',$_POST['user_group_name']); $user_group_id = $_POST['user_group_id']; $smarty_obj->assign('user_group_id',$user_group_id); } //{{{ check that the user is not trying delete a group that is still in use $chk_query = "SELECT `authUserId`,COUNT(`user_gid`) AS `user_count` FROM `liveuser_users` WHERE `user_gid` = '$user_group_id' GROUP BY `user_gid`"; $gr_res = $db->query($chk_query); if (handleError($gr_res)) { if(0!=$gr_res->numRows()) { $gr_res->fetchInto($gr_row); $count_users = $gr_row['user_count']; //{{{ add basic form elements $form->addElement('header',"hdrTop","Unable to Delete Group!"); $form->addElement('header','hdrUserCount',"There are still $count_users users associated with this group!"); //}}} } else { //{{{ create elements $form->addElement('header','hdrTop','Delete Existing Group'); $form->addElement('submit','btnDelete','Confirm Deletion!'); //}}} } } //}}} break; default : $form = new HTML_Quickform('NewForm','POST','groups.php'); $smarty_obj = new SmartyQFWrapper('group_form.tpl'); $smarty_obj->assign('access_denied','true'); }//end of switch //{{{ assign admin access in header.tpl.html menu if('0'==$user_gid) { $smarty_obj->assign('admin','true'); } //}}} if($form->validate()) { $result= $form->process('process_data',false); $form->addElement('text','txtResult',$result); } $smarty_obj->display($form); //}}} /** * process_data * * callback function do all the processing for the form */ function process_data($args) { global $form; global $db; if ('Add a new group'==$args['btnAddEdit']) { $sel_query = "SELECT `user_group_id` FROM `user_groups` WHERE `user_group_name` = '".$args['txtGroupName']."'"; $sel_res = $db->query($sel_query); if(handleError($sel_res)) { if(0==$sel_res->numRows()) { $ins_query = "INSERT INTO `user_groups` (`user_group_id`,`user_group_name`) VALUES ('','".$args['txtGroupName']."')"; $ins_res= $db->query($ins_query); if(handleError($ins_res)) { return "Group inserted successfully"; } else { return "Unable to insert Group!"; } } else { return "There is already a group with that name, please choose a different name for the group."; } } else { return "Unable to check if group already exists"; } } if ('Edit group'==$args['btnAddEdit']) { $upd_query = "UPDATE `user_groups` SET `user_group_name` = '".$args['txtGroupName']."' WHERE `user_group_id` = '".$args['user_group_id']."'"; $upd_res = $db->query($upd_query); if(handleError($upd_res)) { return "Group updated successfully"; } else { return "Unable to update Group!"; } } if (isset($args['btnDelete'])&&('Confirm Deletion!'==$args['btnDelete'])) { $form->addElement('header',"hdrConfirm","Are you sure you want to delete this user group?"); $ele=&$form->getElement('btnDelete'); $ele->setValue('Delete Group!'); } if (isset($args['btnDelete'])&&('Delete Group!'==$args['btnDelete'])) { $del_query = "DELETE FROM `user_groups` WHERE `user_group_id` = '".$args['user_group_id']."'"; $del_res= $db->query($del_query); if(handleError($del_res)) { return "Group deleted successfully"; } else { return "Unable to delete Group"; } } } // end of function process_data ?>