From 3816e3ba559114294f24d04a874e378175f22e0d Mon Sep 17 00:00:00 2001 From: bugrain Date: Fri, 14 Aug 2009 23:22:38 +0000 Subject: [PATCH] Chnages to make batch processing common code reusable - moved setting up of drop down list to form handler, made JavaScript unobtrusive First stab at a datepicker function for form handler - very basic Some tidying up in download plugin --- e107_admin/users.php | 77 ++++++++-------- e107_files/e_css.php | 7 +- e107_files/jslib/e107.js.php | 25 ++++-- e107_handlers/form_handler.php | 89 +++++++++++++++++-- e107_plugins/download/admin_download.php | 11 +-- .../download/handlers/adminDownload_class.php | 70 +++------------ .../languages/English/admin_download.php | 6 +- 7 files changed, 162 insertions(+), 123 deletions(-) diff --git a/e107_admin/users.php b/e107_admin/users.php index acdaaf154..2f05e5b29 100644 --- a/e107_admin/users.php +++ b/e107_admin/users.php @@ -10,9 +10,9 @@ * Administration Area - Users * * $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $ -* $Revision: 1.51 $ -* $Date: 2009-08-10 15:34:28 $ -* $Author: e107coders $ +* $Revision: 1.52 $ +* $Date: 2009-08-14 23:22:36 $ +* $Author: bugrain $ * */ require_once ('../class2.php'); @@ -1111,40 +1111,30 @@ class users function show_batch_options() { - - $text = " -  "; - return $text; + $removeClasses = $assignClasses; // Userclass list of userclasses that can be removed + $removeClasses[0] = array('userclass_name'=>array('userclass_id'=>0, 'userclass_name'=>USRLAN_220)); + return $frm->batchoptions( + array( + 'ban_selected' =>USRLAN_30, + 'unban_selected' =>USRLAN_33, + 'activate_selected' =>USRLAN_32, + 'delete_selected' =>LAN_DELETE + ), + array( + 'userclass' =>array('Assign Userclass...',$assignClasses), + 'remuserclass' =>array('Remove Userclass..', $removeClasses) + ) + ); } @@ -1755,15 +1745,28 @@ class users function user_remuserclass($userid,$uclass) { global $sql,$sql2; - $eu = new e_userclass; - - if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1")) + $emessage = &eMessage::getInstance(); + if ($uclass[0] == 0) { - $row = $sql->db_Fetch(); - $eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class'])); + if($sql->db_Update("user","user_class='' WHERE user_id={$userid}")===TRUE) + { + $emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated; + } + else + { + $emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated; + } + } + else + { + $eu = new e_userclass; + if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1")) + { + $row = $sql->db_Fetch(); + $eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class'])); + } + $emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated; } - $emessage = &eMessage::getInstance(); - $emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated; } // Set userclass for user(s). diff --git a/e107_files/e_css.php b/e107_files/e_css.php index 29fe6c0ed..3d1a31ef6 100644 --- a/e107_files/e_css.php +++ b/e107_files/e_css.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_files/e_css.php,v $ -| $Revision: 1.1 $ -| $Date: 2009-08-06 22:41:35 $ +| $Revision: 1.2 $ +| $Date: 2009-08-14 23:22:36 $ | $Author: bugrain $ +---------------------------------------------------------------+ */ @@ -45,7 +45,8 @@ echo " display: block; } a.e-hide-if-js, - span.e-hide-if-js { + span.e-hide-if-js, + button.e-hide-if-js { display: inline; } diff --git a/e107_files/jslib/e107.js.php b/e107_files/jslib/e107.js.php index 7d4cc25f4..a9389dab7 100644 --- a/e107_files/jslib/e107.js.php +++ b/e107_files/jslib/e107.js.php @@ -8,9 +8,9 @@ * e107 Javascript API * * $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $ - * $Revision: 1.33 $ - * $Date: 2009-07-21 10:27:26 $ - * $Author: secretr $ + * $Revision: 1.34 $ + * $Date: 2009-08-14 23:22:36 $ + * $Author: bugrain $ * */ @@ -873,6 +873,21 @@ Object.extend(e107Helper, { }); }, + /** + * + * + */ + executeBatch: function(event) { + var element = event.memo['element'] ? $(event.memo.element) : $$('body')[0]; + Element.select(element, 'select.e-execute-batch').invoke('observe', 'change', function(e) { + var frm = e.element().up('form'); + if (frm) { + frm.submit(); + e.stop(); + } + }); + }, + /** * added as Element method below */ @@ -1158,7 +1173,7 @@ e107Helper.BB = { if (!this.__selectedInputArea) { return; //[SecretR] TODO - alert the user } - var eField = this.__selectedInputArea, + var eField = this.__selectedInputArea, tags = this.parse(text, emote), scrollPos, sel, newStart; if(this.insertIE(eField, text, tags)) return; @@ -2670,6 +2685,6 @@ function sendInfo(handler, container, form) { /* * Core Auto-load */ -$w('autoExternalLinks autoNoHistory autoHide toggleObserver toggleManyObserver scrollToObserver').each( function(f) { +$w('autoExternalLinks autoNoHistory autoHide toggleObserver toggleManyObserver scrollToObserver executeBatch').each( function(f) { e107.runOnLoad(e107Helper[f], null, true); }); diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 772c2fab2..9dadcd8e3 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,9 +9,9 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.37 $ - * $Date: 2009-07-21 16:05:10 $ - * $Author: e107coders $ + * $Revision: 1.38 $ + * $Date: 2009-08-14 23:22:37 $ + * $Author: bugrain $ * */ @@ -65,7 +65,7 @@ class e_form var $_tabindex_counter = 0; var $_tabindex_enabled = true; var $_cached_attributes = array(); - + /** * @var user_class */ @@ -108,6 +108,35 @@ class e_form return $ret; } + /** + * Date field with popup calendar + * @param name => string - the name of the field + * @param datestamp => UNIX timestamp - default value of the field + **/ + function datepicker($name, $datestamp=false) + { + global $pref; + //TODO can some of these values be set in an admin section somewhere so they are set per site? + //TODO allow time option ? + $cal = new DHTML_Calendar(true); + $cal_options['showsTime'] = false; + $cal_options['showOthers'] = false; + $cal_options['weekNumbers'] = false; + //TODO use $prefs values for format? + $cal_options['ifFormat'] = $pref['inputdate']; + $cal_options['timeFormat'] = "24"; + $cal_attrib['class'] = "tbox"; + $cal_attrib['size'] = "12"; + $cal_attrib['name'] = $name; + if ($datestamp) + { + //TODO use $prefs values for format? + $cal_attrib['value'] = date("d/m/Y H:i:s", $datestamp); + $cal_attrib['value'] = date("d/m/Y", $datestamp); + } + return $cal->make_input_field($cal_options, $cal_attrib); + } + function file($name, $options = array()) { $options = $this->format_options('file', $name, $options); @@ -260,7 +289,7 @@ class e_form { if($classnum == e_UC_BLANK) return $this->option(' ', ''); - + $tmp = explode(',', $current_value); if($nest_level == 0) { @@ -277,7 +306,7 @@ class e_form $prefix = '  '.str_repeat('--', $nest_level - 1).'>'; $style = ''; } - return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), "style={$style}")."\n"; + return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), array("style"=>"{$style}"))."\n"; } function optgroup_open($label, $disabled) @@ -492,7 +521,7 @@ class e_form } /** - * Get default options array based on the filed type + * Get default options array based on the field type * * @param string $type * @return array default options @@ -580,10 +609,10 @@ class e_form function columnSelector($columnsArray,$columnsDefault='',$id='column_options') { $text = "
- + select columns -
\n"; +
\n"; unset($columnsArray['options']); foreach($columnsArray as $key=>$fld) @@ -732,6 +761,48 @@ class e_form } // This needs to be dynamic for the various form types, and be loaded via ajax. } + + /** + * Generates a batch options select component + * This component is generally associated with a table of items where one or more rows in the table can be selected (using checkboxes). + * The list options determine some processing that wil lbe applied to all checked rows when the form is submitted. + * @param options => array - associative array of option elements, keyed on the option value + * @param ucOptions => array - associative array of userclass option groups to display, keyed on the option value prefix + * @return the HTML for the form component + */ + function batchoptions($options, $ucOptions=null) { + $text = " +
+ + + +
+  "; + return $text; + } } class form { diff --git a/e107_plugins/download/admin_download.php b/e107_plugins/download/admin_download.php index b0c5b96f2..0c5bdf151 100644 --- a/e107_plugins/download/admin_download.php +++ b/e107_plugins/download/admin_download.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $ -| $Revision: 1.10 $ -| $Date: 2009-08-06 22:36:17 $ +| $Revision: 1.11 $ +| $Date: 2009-08-14 23:22:37 $ | $Author: bugrain $ +----------------------------------------------------------------------------+ */ @@ -834,12 +834,5 @@ function admin_download_adminmenu($parms) $var['mirror']['text'] = DOWLAN_128; $var['mirror']['link'] = e_SELF."?mirror"; e_admin_menu(DOWLAN_32, $action, $var); - - unset($var); - if ($action == "" || $action == "main") { - $var['1']['text'] = "//TODO"; - $var['1']['link'] = ""; - e_admin_menu(DOWLAN_184, $subAction, $var); - } } ?> \ No newline at end of file diff --git a/e107_plugins/download/handlers/adminDownload_class.php b/e107_plugins/download/handlers/adminDownload_class.php index 8f9647d69..362ae1106 100644 --- a/e107_plugins/download/handlers/adminDownload_class.php +++ b/e107_plugins/download/handlers/adminDownload_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $ -| $Revision: 1.15 $ -| $Date: 2009-08-06 22:41:34 $ +| $Revision: 1.16 $ +| $Date: 2009-08-14 23:22:37 $ | $Author: bugrain $ | +----------------------------------------------------------------------------+ @@ -60,30 +60,6 @@ class adminDownload extends download // Search field $text .= "
"; } $text .= "
"; @@ -465,37 +441,17 @@ class adminDownload extends download } // --------------------------------------------------------------------------- - function batch_options() + function batch_options() { - $text = " -  "; - return $text; + $frm = new e_form(); + $classes = get_userclass_list(); + return $frm->batchoptions( + array('delete_selected'=>LAN_DELETE), + array( + 'userclass' =>array('Assign userclass...',$classes), + 'visibility'=>array('Assign Visibility..',$classes) + ) + ); } diff --git a/e107_plugins/download/languages/English/admin_download.php b/e107_plugins/download/languages/English/admin_download.php index 2bcf7a660..0f011e698 100644 --- a/e107_plugins/download/languages/English/admin_download.php +++ b/e107_plugins/download/languages/English/admin_download.php @@ -4,8 +4,8 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/languages/English/admin_download.php,v $ -| $Revision: 1.6 $ -| $Date: 2009-07-18 19:04:04 $ +| $Revision: 1.7 $ +| $Date: 2009-08-14 23:22:38 $ | $Author: bugrain $ +----------------------------------------------------------------------------+ */ @@ -185,7 +185,7 @@ define("DOWLAN_180", "File size (database/disk)"); define("DOWLAN_181", "Not readable"); define("DOWLAN_182", "Timestamp"); define("DOWLAN_183", "Advanced search"); -define("DOWLAN_184", "Batch options"); +define("DOWLAN_184", ""); define("DOWLAN_185", "Files referenced multiple times in the database"); define("DOWLAN_186", "Files not referenced in the database"); define("DOWLAN_187", "Database entries referencing non-existent files");