diff --git a/e107_admin/userclass2.php b/e107_admin/userclass2.php index cefbdd41c..02a30ae1c 100644 --- a/e107_admin/userclass2.php +++ b/e107_admin/userclass2.php @@ -2,15 +2,12 @@ /* * e107 website system * - * Copyright (C) 2008-2010 e107 Inc (e107.org) + * Copyright (C) 2008-2015 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * Administration Area - User classes * - * $URL$ - * $Id$ - * */ @@ -31,6 +28,430 @@ if (!getperms('4')) include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE); + + + + class uclass_admin extends e_admin_dispatcher + { + + protected $modes = array( + + 'main' => array( + 'controller' => 'uclass_ui', + 'path' => null, + 'ui' => 'uclass_ui_form', + 'uipath' => null + ), + + + ); + + + protected $adminMenu = array( + + 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => '4'), + 'main/create' => array('caption'=> LAN_CREATE, 'perm' => '4'), + 'main/initial' => array('caption'=> UCSLAN_38, 'perm' => '4'), + 'main/options' => array('caption'=> LAN_OPTIONS, 'perm' => '4'), + + // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P') + ); + + protected $adminMenuAliases = array( + 'main/edit' => 'main/list' + ); + + protected $menuTitle = ADLAN_38; + } + + + + + class uclass_ui extends e_admin_ui + { + + protected $pluginTitle = ADLAN_38; + protected $pluginName = 'core'; +// protected $eventName = 'userclass'; + protected $table = 'userclass_classes'; + protected $pid = 'userclass_id'; + protected $perPage = 10; + protected $batchDelete = true; + protected $batchCopy = true; + protected $listOrder = 'userclass_id DESC'; + // protected $sortField = 'somefield_order'; + // protected $orderStep = 10; + // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. + + // protected $listQry = "SELECT * FROM `#generic` WHERE gen_type='wmessage' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. + + // protected $listOrder = 'gen_id DESC'; + + + + protected $fields = array( + 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect', ), + 'userclass_id' => array('title'=> LAN_ID, 'type' =>'hidden', 'data'=>'int', 'width' => '5%', 'thclass' => 'left'), + 'userclass_icon' => array('title'=> UCSLAN_68, 'type' => 'icon', 'data'=>'str', 'width' => '5%', 'thclass' => 'left', 'class' => 'center'), + 'userclass_name' => array('title'=> UCSLAN_12, 'type' => 'text', 'data'=>'str', 'width' => 'auto', 'thclass' => 'left'), + 'userclass_description' => array('title'=> UCSLAN_13, 'type' => 'text', 'data'=>'str', 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>array('size'=>'xxlarge')), + 'userclass_type' => array('title'=> UCSLAN_79, 'type' => 'dropdown', 'data'=>'int', 'width' => '10%', 'thclass' => 'left', 'class'=>'left' ), + 'userclass_editclass' => array('title'=> UCSLAN_24, 'type' => 'userclass', 'data'=>'int', 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>array('classlist'=>'nobody,public,main,admin,classes,matchclass,member, no-excludes')), + 'userclass_visibility' => array('title'=> UCSLAN_34, 'type' => 'userclass', 'data'=>'int', 'width' => 'auto', 'thclass' => 'left'), + 'userclass_parent' => array('title'=> UCSLAN_35, 'type' => 'userclass', 'data'=>'int', 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>array('classlist'=>'main,admin,nobody,public,classes,matchclass,member, no-excludes')), + + 'options' => array('title'=> LAN_OPTIONS, 'type' => 'method', 'width' => '10%', 'thclass' => 'center last', 'forced'=>TRUE, 'class'=>'right', 'readParms' => array('deleteClass' => e_UC_NOBODY)) + ); + + protected $fieldpref = array('userclass_icon', 'userclass_name', 'userclass_description'); + + /* + protected $prefs = array( + 'wm_enclose' => array('title'=> WMLAN_05, 'type'=>'boolean', 'data' => 'int','help'=> WMLAN_06), );*/ + + public function init() + { + + // Listen for submitted data. + $this->initialPageSubmit(); + $this->optionsPageSubmit(); + + if($this->getAction() == 'list') + { + $this->fields['userclass_id']['type'] = 'number'; + } + + // Set Defaults for when creating new records. + $this->fields['userclass_type']['writeParms'] = array(UC_TYPE_STD => UCSLAN_80, UC_TYPE_GROUP => UCSLAN_81); + $this->fields['userclass_editclass']['writeParms']['default'] = e_UC_ADMIN; + $this->fields['userclass_parent']['writeParms']['default'] = e_UC_NOBODY; + $this->fields['userclass_visibility']['writeParms']['default'] = e_UC_ADMIN; + $this->fields['userclass_id']['writeParms']['default'] =$this->getUserClassAdmin()->findNewClassID(); + + } + + public function getUserClassAdmin() + { + return e107::getSingleton('user_class_admin'); + } + + public function beforeCreate($new_data) + { + return $new_data; + } + + public function afterCreate($new_data, $old_data, $id) + { + // do something + } + + public function beforeUpdate($new_data, $old_data, $id) + { + return $new_data; + } + + public function afterUpdate($new_data, $old_data, $id) + { + // e107::getCache()->clear("wmessage"); + } + + public function onCreateError($new_data, $old_data) + { + // do something + } + + public function onUpdateError($new_data, $old_data, $id) + { + // do something + } + + + public function optionsPage() + { + $mes = e107::getMessage(); + $frm = e107::getForm(); + + + $mes->addWarning(UCSLAN_52."
".UCSLAN_53); + + $text = "

".LAN_PREFS."

+
+ + + + + + + + + + "; + + /* + if ($params == '.xml') + { + $text .= " + + "; + + } + */ + + $text .= "
".UCSLAN_54."
".UCSLAN_57."
+
+ ".$frm->admin_button('add_class_tree','no-value','delete', UCSLAN_58)." +
".UCSLAN_55."
".UCSLAN_56."
+
+ ".$frm->admin_button('flatten_class_tree','no-value','delete', UCSLAN_58)." +
".'Create XML file of DB'."
".'Dev aid to set initial values'."
+
+ ".$frm->admin_button('create_xml_db','no-value','create', 'Create')." +
"; + + + + // $ns->tablerender(ADLAN_38.SEP.LAN_PREFS, $mes->render().$text); + + + $text .= " +

".UCSLAN_71."

+ + + + + + + + + +
".UCSLAN_72."
+ ".UCSLAN_73." +
+ ".$frm->admin_button('rebuild_tree','no-value','delete', UCSLAN_58)." +
+
"; + + // $ns->tablerender(UCSLAN_71, $text); + return $text; + + } + + + public function optionsPageSubmit() + { + + if (!check_class(e_UC_MAINADMIN)) + { + return false; + } + + $ns = e107::getRender(); + $sql = e107::getDb(); + $mes = e107::getMessage(); + $e_userclass = $this->getUserClassAdmin(); + + if (isset($_POST['add_class_tree'])) // Create a default tree + { + $message = UCSLAN_62; + $e_userclass->set_default_structure(); + $e_userclass->calc_tree(); + $e_userclass->save_tree(); + $e_userclass->readTree(TRUE); // Need to re-read the tree to show correct info + $message .= UCSLAN_64; + } + + if (isset($_POST['flatten_class_tree'])) // Remove the default tree + { + $message = UCSLAN_65; + $sql->update('userclass_classes', "userclass_parent='0'"); + $e_userclass->calc_tree(); + $e_userclass->save_tree(); + $e_userclass->readTree(TRUE); // Need to re-read the tree to show correct info + $message .= UCSLAN_64; + } + + if (isset($_POST['rebuild_tree'])) + { + $message = UCSLAN_70; + $e_userclass->calc_tree(); + $e_userclass->save_tree(); + $message .= UCSLAN_64; + } + + /* + if ($params == 'xml') $params = '.xml'; else $params = ''; + + if (isset($_POST['create_xml_db']) && ($params == '.xml')) + { + $message = $e_userclass->makeXMLFile() ? 'XML file created' : 'Error creating XML file'; + } + */ + + if ($message) + { + $mes->addSuccess($message); + // $ns->tablerender('', "
".$message."
"); + } + + } + + + + public function initialPage() + { + + $pref = e107::pref('core'); + $mes = e107::getMessage(); + $ns = e107::getRender(); + $frm = e107::getForm(); + // $e_userclass = $this->getUserClassAdmin(); + + $text = ""; + + $initial_classes = varset($pref['initial_user_classes'],''); + + $irc = explode(',',$initial_classes); + $icn = array(); + + foreach ($irc as $i) + { + if (trim($i)) $icn[] = e107::getUserClass()->uc_get_classname($i); + } + + $class_text = $frm->userclass('init_classes',$initial_classes, 'checkbox', 'classes,force'); + + // $class_text = e107::getUserClass()->uc_checkboxes('init_classes', $initial_classes, 'classes, force', TRUE); + // $class_text = e107::getUserClass()->vetted_tree('init_classes',array($e_userclass,'checkbox_desc'), $initial_classes, 'classes, force, no-excludes'); + + $mes->addInfo(UCSLAN_49); + + $text = "
+
+ + +
".UCSLAN_43.""; + + if (count($icn) > 0) + { + // $text .= implode(', ',$icn); + } + else + { + $text .= UCSLAN_44; + } + + + if ($class_text) + { + $text .= $class_text."
"; + $sel_stage = varset($pref['init_class_stage'],2); + + $initClassStages = array(1 =>UCSLAN_47, 2=>UCSLAN_48); + + $text .= UCSLAN_45."
".$frm->select('init_class_stage', $initClassStages, $sel_stage)."".UCSLAN_46." + +
+
". $frm->admin_button('set_initial_classes','no-value','create',LAN_UPDATE)."
"; + } + else + { + $text .= UCSLAN_39; + } + + $text .= "
"; + return $mes->render() . $text; + // $ns->tablerender(ADLAN_38.SEP.UCSLAN_40, $mes->render() . $text); + + } + + + /** + * @return bool + */ + public function initialPageSubmit() + { + if(empty($_POST['set_initial_classes'])) + { + return false; + } + + $pref['init_class_stage'] = intval($_POST['init_class_stage']); + + $temp = array(); + + foreach ($_POST['init_classes'] as $ic) + { + $temp[] = intval($ic); + } + + $newval = implode(',', $temp); + + $pref['initial_user_classes'] = $newval; + + e107::getConfig()->setPref($pref)->save(true,true,true); + } + + + + + } + + + + class uclass_ui_form extends e_admin_form_ui + { + function userclass_type($curVal,$mode) + { + $types = array( + UC_TYPE_STD => UCSLAN_80, + UC_TYPE_GROUP => UCSLAN_81 + ); + + return varset($types[$curVal]); + } + + function options($parms, $value, $id, $attributes) + { + + $text = ""; + + if($attributes['mode'] == 'read') + { + + $classID = $this->getController()->getListModel()->get('userclass_id'); + + if(!$this->getController()->getUserClassAdmin()->queryCanDeleteClass($classID)) + { + $options = array('deleteClass' => e_UC_NOBODY); + } + + $text .= $this->renderValue('options',$value, $options,$id); + + // if($parent != 0) + { + // $link = e_SELF."?searchquery=&filter_options=page_chapter__".$id."&mode=page&action=list"; + // $text .= "".E_32_CUST.""; + } + + return $text; + } + } + + } + + + new uclass_admin(); + + require_once(e_ADMIN."auth.php"); + + e107::getAdminUI()->runPage(); + + require_once(e_ADMIN."footer.php"); + exit; + + + + $e_sub_cat = 'userclass'; //define('UC_DEBUG_OPTS',FALSE); @@ -42,7 +463,7 @@ require_once(e_HANDLER.'form_handler.php'); $frm = new e_form(); -$uc = new uclass_manager; +// $uc = new uclass_manager; $mes = e107::getMessage(); @@ -102,6 +523,7 @@ $params = varset($uc_qs[1],''); e107::setRegistry('pageParams', $uc_qs); //AJAX request check is already made by the API +/* if(e_AJAX_REQUEST) { $class_num = intval($params); @@ -157,6 +579,7 @@ if(e_AJAX_REQUEST) } e107::getJs()->headerCore('core/admin.js'); +*/ /* * Authorization should be done a bit later! @@ -167,6 +590,7 @@ $emessage = e107::getMessage(); //--------------------------------------------------- // Set Initial Classes //--------------------------------------------------- +/* if (isset($_POST['set_initial_classes'])) { $changed = $pref['init_class_stage'] != intval($_POST['init_class_stage']); @@ -191,11 +615,13 @@ if (isset($_POST['set_initial_classes'])) $message = UCSLAN_42; } } - +*/ //--------------------------------------------------- // Delete existing class //--------------------------------------------------- + +/* if (isset($_POST['etrigger_delete']) && !empty($_POST['etrigger_delete'])) { $classID = intval(array_shift(array_keys($_POST['etrigger_delete']))); @@ -219,11 +645,11 @@ if (isset($_POST['etrigger_delete']) && !empty($_POST['etrigger_delete'])) { $e_pref->removePref('frontpage/'.$classID)->save(false); } - /*if (isset($pref['frontpage'][$class_id])) + // if (isset($pref['frontpage'][$class_id])) { - unset($pref['frontpage'][$class_id]); // (Should work with both 0.7 and 0.8 front page methods) - save_prefs(); - }*/ + // unset($pref['frontpage'][$class_id]); // (Should work with both 0.7 and 0.8 front page methods) + // save_prefs(); + } $emessage->add(UCSLAN_3, E_MESSAGE_SUCCESS); } else @@ -235,13 +661,15 @@ if (isset($_POST['etrigger_delete']) && !empty($_POST['etrigger_delete'])) { $emessage->add(UCSLAN_10, E_MESSAGE_ERROR); } -} +}*/ //--------------------------------------------------- // Add/Edit class information //--------------------------------------------------- +/* + if (isset($_POST['createclass'])) // Add or edit { $fullEdit = TRUE; // Most of the time, we are allowed to edit everything @@ -345,9 +773,9 @@ if (isset($_POST['createclass'])) // Add or edit $e_userclass->save_tree(); } } +*/ - - +/* if ($message) { $emessage->add($message); @@ -365,15 +793,16 @@ class uclassFrm extends e_form return varset($types[$curVal]); } } +*/ - - +/* if(!e_QUERY || $action == 'list') { $uc->show_existing(); } +*/ if(isset($_GET['id']) && $_GET['action'] == 'edit') { $action = 'config'; @@ -573,7 +1002,9 @@ unset($title); //----------------------------------- // Initial User class(es) //----------------------------------- +/* case 'initial' : + $initial_classes = varset($pref['initial_user_classes'],''); $irc = explode(',',$initial_classes); $icn = array(); @@ -626,7 +1057,7 @@ unset($title); $ns->tablerender(ADLAN_38.SEP.UCSLAN_40, $mes->render() . $text); break; // End of 'initial' - +*/ //----------------------------------- // Debug aids @@ -657,6 +1088,7 @@ unset($title); // Configuration options //----------------------------------- case 'options' : + /* if (!check_class(e_UC_MAINADMIN)) break; if (isset($_POST['add_class_tree'])) @@ -755,7 +1187,7 @@ unset($title); $ns->tablerender(UCSLAN_71, $text); break; // End of 'options' - +*/ //----------------------------------- // Test options @@ -893,7 +1325,7 @@ function userclass2_adminlog($msg_num='00', $woffle='') e107::getAdminLog()->log_event('UCLASS_'.$msg_num,$woffle,E_LOG_INFORMATIVE,''); } - +/* function userclass2_adminmenu() { $tmp = array(); @@ -912,10 +1344,10 @@ function userclass2_adminmenu() $var['config']['link'] = 'userclass2.php?config'; //DEPRECATED - use admin->users instead. -/* - $var['membs']['text'] = UCSLAN_26; - $var['membs']['link'] ='userclass2.php?membs'; -*/ + +// $var['membs']['text'] = UCSLAN_26; +// $var['membs']['link'] ='userclass2.php?membs'; + $var['initial']['text'] = UCSLAN_38; $var['initial']['link'] ='userclass2.php?initial'; @@ -939,11 +1371,16 @@ function userclass2_adminmenu() } show_admin_menu(ADLAN_38, $action, $var); } +*/ + function e_help() { +// require_once(e_HANDLER.'userclass_class.php'); // Modified class handler +// $e_userclass = new user_class_admin; + $e_userclass = e107::getSingleton('user_class_admin'); // Admin functions - should just obliterate any previous object created in class2.php - global $e_userclass; + $e_userclass->calc_tree(); $text2 = "
".$e_userclass->show_graphical_tree()."
"; $help = e_LANGUAGEDIR.e_LANGUAGE.'/admin/help/userclass2.php'; @@ -960,6 +1397,9 @@ function e_help() } + +/* + class uclass_manager { public function __construct() @@ -988,9 +1428,9 @@ class uclass_manager } - /** - * Show list of existing userclasses, followed by graphical tree of the hierarchy - */ + +// Show list of existing userclasses, followed by graphical tree of the hierarchy + public function show_existing() { global $e_userclass; @@ -1037,7 +1477,7 @@ class uclass_manager } require_once(e_ADMIN.'footer.php'); - +*/ // @TODO: Is this function still required? - Yes - setGroupStatus() used on class add/edit page diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index bc96462f5..5a76c7ed2 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -3975,7 +3975,7 @@ class e_admin_controller_ui extends e_admin_controller $id = $model->getId(); // Trigger Admin-ui event. 'post' - if($triggerName = $this->getEventTriggerName($_posted['etrigger_submit']).'d') // 'created' or 'updated'; + if($triggerName = $this->getEventTriggerName($_posted['etrigger_submit'],'after')) // 'created' or 'updated'; { $eventData = array('newData'=>$_posted,'oldData'=>$old_data,'id'=> $id); $model->addMessageDebug('Admin-ui Trigger fired: '.$triggerName.' with data '.print_a($eventData,true)); @@ -4006,16 +4006,26 @@ class e_admin_controller_ui extends e_admin_controller return false; } - /** Return a custom event trigger name + + /** + * Return a custom event trigger name + * @param null $type Usually 'Create' or 'Update' + * @param string $when ' before or after + * @return bool|string */ - public function getEventTriggerName($type=null) + public function getEventTriggerName($type=null, $when='before') { $plug = $this->getEventName(); if(empty($plug) || empty($type)) { return false; - } + } + + if($when == 'after') + { + $type .= 'd'; // ie. 'created' or 'updated'. + } return 'admin_'.strtolower($plug).'_'.strtolower($type); @@ -4231,7 +4241,7 @@ class e_admin_ui extends e_admin_controller_ui // send messages to session e107::getMessage()->moveToSession(); // redirect - $this->redirect(); + $this->redirect(); } /** diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 7bf3fe119..5899ed6d2 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -208,6 +208,7 @@ class e107 'sitelinks' => '{e_HANDLER}sitelinks_class.php', 'themeHandler' => '{e_HANDLER}theme_handler.php', 'user_class' => '{e_HANDLER}userclass_class.php', + 'user_class_admin' => '{e_HANDLER}userclass_class.php', 'userlogin' => '{e_HANDLER}login.php', 'validatorClass' => '{e_HANDLER}validator_class.php', 'xmlClass' => '{e_HANDLER}xml_class.php', diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 499eea382..209c8c059 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -1683,7 +1683,7 @@ class e_form switch ($type) { case 'checkbox': - return e107::getUserClass()->uc_checkboxes($name,$curval,$options,null,true); + return e107::getUserClass()->uc_checkboxes($name,$curval,$options,null,false); break; case 'dropdown': diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index f4a8ec811..a24a04e09 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -92,9 +92,10 @@ class e_object */ public function getId() { + if ($this->getFieldIdName()) { - return $this->get($this->getFieldIdName(), null); + return $this->get($this->getFieldIdName(), 0); // default of NULL will break MySQL strict in most cases. } return $this->get('id', 0); } @@ -2596,7 +2597,7 @@ class e_front_model extends e_model if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES) { - $this->addMessageDebug('SQL Qry: '.print_a($qry,true), $session_messages); + $this->addMessageDebug('SQL Qry: '.print_a($qry,true), null); } return $qry; } @@ -2853,7 +2854,7 @@ class e_admin_model extends e_front_model $this->mergePostedData(false, true, true); } - if($this->getId()) + if($this->getId() && $this->getPostedData('etrigger_submit') !='Create') // Additional Check to allow primary ID to be manually set when auto-increment PID is not used. @see userclass2.php { return $this->dbUpdate($force, $session_messages); } diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 89edb8e68..4617e8b64 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -1932,7 +1932,8 @@ class e_db_mysql } $id = $this->gen("INSERT INTO #".$table."(".$fieldList.") SELECT ".$fieldList." FROM #".$table." WHERE ".$args); - return $this->lastInsertId(); + $lastInsertId = $this->lastInsertId(); + return ($id && $lastInsertId) ? $lastInsertId : false; } diff --git a/e107_handlers/userclass_class.php b/e107_handlers/userclass_class.php index f63d3cd51..656e5f9ea 100644 --- a/e107_handlers/userclass_class.php +++ b/e107_handlers/userclass_class.php @@ -570,8 +570,8 @@ class user_class $c = (in_array($k,$curArray)) ? true : false; if ($showdescription) $v .= ' ('.$this->uc_get_classdescription($k).')'; //$ret[] = "
\n"; - - $ret[] = $frm->checkbox($fieldname[$k],$k,$c,$v); + $name = $fieldname.'['.$k.']'; + $ret[] = $frm->checkbox($name,$k,$c,$v); //$ret[] = "
\n"; } @@ -1193,6 +1193,7 @@ class user_class_admin extends user_class } + /* * Internal function, called recursively to rebuild the permissions tree where rights increase going down the tree * If the permissions change, sets the 'change_flag' to force rewrite to DB (by other code) @@ -1542,7 +1543,8 @@ class user_class_admin extends user_class { if (!$classrec['userclass_id']) { - echo 'Programming bungle on save - no ID field
'; + e107::getMessage()->addDebug('Programming bungle on save - no ID field'); + // echo 'Programming bungle on save - no ID field
'; return FALSE; } $qry = ''; @@ -1813,9 +1815,9 @@ class user_class_admin extends user_class foreach ($init_list as $entry) { - if ($this->sql_r->db_Select('userclass_classes','*',"userclass_id='".$entry['userclass_id']."' ")) + if ($this->sql_r->select('userclass_classes','*',"userclass_id='".$entry['userclass_id']."' ")) { - $this->sql_r->db_Update('userclass_classes', "userclass_parent='".$entry['userclass_parent']."', userclass_visibility='".$entry['userclass_visibility']."' WHERE userclass_id='".$entry['userclass_id']."'"); + $this->sql_r->update('userclass_classes', "userclass_parent='".$entry['userclass_parent']."', userclass_visibility='".$entry['userclass_visibility']."' WHERE userclass_id='".$entry['userclass_id']."'"); } else {