diff --git a/e107_admin/comment.php b/e107_admin/comment.php index b4387e8bc..5dc77bafb 100644 --- a/e107_admin/comment.php +++ b/e107_admin/comment.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/comment.php,v $ -| $Revision: 1.17 $ -| $Date: 2009-11-09 16:54:30 $ +| $Revision: 1.18 $ +| $Date: 2009-11-10 19:13:07 $ | $Author: secretr $ +----------------------------------------------------------------------------+ */ @@ -65,7 +65,7 @@ class comments_admin_ui extends e_admin_ui * @var array [optional] */ protected $tableJoin = array ( - 'user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => '', 'where' => ''*/) + 'u.user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => 'AND u.user_ban=0', 'where' => ''*/) ); //protected $listQry = "SELECT SQL_CALC_FOUND_ROWS * FROM #comments"; // without any Order or Limit. @@ -85,7 +85,7 @@ class comments_admin_ui extends e_admin_ui 'comment_comment' => array('title'=> "comment", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'comment_author_id' => array('title'=> "authorID", 'type' => 'user', 'data' => 'int', 'width' => 'auto'), // User id 'comment_author_name' => array('title'=> "authorName", 'type' => 'text', 'width' => 'auto'), // User name - 'user_name' => array('title'=> "System user", 'type' => 'text', 'width' => 'auto', 'table' => 'user', 'noedit' => true), // User name + 'u.user_name' => array('title'=> "System user", 'type' => 'text', 'width' => 'auto', 'noedit' => true), // User name 'comment_datestamp' => array('title'=> "datestamp", 'type' => 'datestamp', 'width' => 'auto'), // User date 'comment_blocked' => array('title'=> "blocked", 'type' => 'boolean', 'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo 'comment_ip' => array('title'=> "IP", 'type' => 'ip', 'width' => '10%', 'thclass' => 'center' ), // Real name (no real vetting) diff --git a/e107_files/jslib/core/admin.js b/e107_files/jslib/core/admin.js index 82e02b5c8..ccf3e7425 100644 --- a/e107_files/jslib/core/admin.js +++ b/e107_files/jslib/core/admin.js @@ -8,8 +8,8 @@ * e107 Admin Helper * * $Source: /cvs_backup/e107_0.8/e107_files/jslib/core/admin.js,v $ - * $Revision: 1.22 $ - * $Date: 2009-11-09 16:55:41 $ + * $Revision: 1.23 $ + * $Date: 2009-11-10 19:13:07 $ * $Author: secretr $ * */ @@ -63,6 +63,14 @@ e107Admin.Helper = { var msg = el.readAttribute('delmsg') || e107.getModLan('delete_confirm'); if( !e107Helper.confirm(msg) ) e.stop(); }); + + element.select('textarea.e-autoheight').each( function (textarea) { + var options = {}, autoopt = '__' + textarea.name + 'autoheight_opt', autooptel = textarea.next('input[name=' + autoopt + ']'); + if(autooptel) { + options['max_length'] = parseInt(autooptel.value); + } + new e107Admin.Nicearea(textarea, options); + }); }, /** diff --git a/e107_handlers/admin_handler.php b/e107_handlers/admin_handler.php index 8813e7e27..1730e35d5 100644 --- a/e107_handlers/admin_handler.php +++ b/e107_handlers/admin_handler.php @@ -1885,6 +1885,7 @@ class e_admin_ui extends e_admin_controller_ui protected $tableJoin; protected $editQry; protected $table; + protected $tableAlias; protected $pid; protected $pluginTitle; @@ -1935,7 +1936,7 @@ class e_admin_ui extends e_admin_controller_ui $this->fieldpref = $ufieldpref; } - $this->addTitle($this->pluginTitle, true); + $this->addTitle($this->pluginTitle, true)->parseAliases(); } /** @@ -2050,17 +2051,7 @@ class e_admin_ui extends e_admin_controller_ui function EditHeader() { // TODO - make it part of e_from::textarea/bbarea(), invoke it on className (not all textarea elements) - e107::getJs()->requireCoreLib('core/admin.js') - ->footerInline(" - \$\$('textarea').each(function(textarea) { - //auto options - var options = {}, autoopt = '__' + textarea.name + '_opt', autooptel = textarea.next('input[name=autoopt]'); - if(autooptel) { - options['max_length'] = parseInt(autooptel.value); - } - new e107Admin.Nicearea(textarea, options); - }); - "); + e107::getJs()->requireCoreLib('core/admin.js'); } /** @@ -2121,17 +2112,7 @@ class e_admin_ui extends e_admin_controller_ui function CreateHeader() { // TODO - make it part of e_from::textarea/bbarea(), invoke it on className (not all textarea elements) - e107::getJs()->requireCoreLib('core/admin.js') - ->footerInline(" - \$\$('textarea').each(function(textarea) { - //auto options - var options = {}, autoopt = '__' + textarea.name + '_opt', autooptel = textarea.next('input[name=autoopt]'); - if(autooptel) { - options['max_length'] = parseInt(autooptel.value); - } - new e107Admin.Nicearea(textarea, options); - }); - "); + e107::getJs()->requireCoreLib('core/admin.js'); } /** @@ -2241,6 +2222,79 @@ class e_admin_ui extends e_admin_controller_ui } } + protected function parseAliases() + { + // parse table + if(strpos($this->table, '.') !== false) + { + $tmp = explode('.', $this->table, 2); + $this->table = $tmp[1]; + $this->tableAlias = $tmp[0]; + unset($tmp); + } + + if($this->tableJoin) + { + foreach ($this->tableJoin as $table => $att) + { + if(strpos($table, '.') !== false) + { + $tmp = explode('.', $table, 2); + unset($this->tableJoin[$table]); + $att['alias'] = $tmp[0]; + $att['table'] = $tmp[1]; + $att['__tablePath'] = $att['alias'].'.'; + $att['__tableFrom'] = '`#'.$att['table'].'` AS '.$att['alias']; + $this->tableJoin[$att['alias']] = $att; + unset($tmp); + continue; + } + $this->tableJoin[$table]['table'] = $table; + $this->tableJoin[$table]['alias'] = ''; + $this->tableJoin[$table]['__tablePath'] = '`#'.$this->tableJoin[$table]['table'].'`.'; + $this->tableJoin[$table]['__tableFrom'] = '`#'.$this->tableJoin[$table]['table'].'`'; + } + } + + // check for table aliases + $fields = array(); // preserve order + foreach ($this->fields as $field => $att) + { + if(strpos($field, '.') !== false) + { + $tmp = explode('.', $field, 2); + $att['alias'] = $tmp[0]; + $fields[$tmp[1]] = $att; + $field = $tmp[1]; + unset($tmp); + } + else + { + $att['alias'] = $this->tableAlias; + $fields[$field] = $att; + } + if($fields[$field]['alias']) + { + + if($fields[$field]['alias'] == $this->tableAlias) + { + $fields[$field]['__tableField'] = $this->tableAlias.'.'.$field; + } + else + { + $fields[$field]['__tableField'] = $this->tableJoin[$fields[$field]['alias']]['__tablePath'].$field; + } + } + else + { + $fields[$field]['__tableField'] = '`#'.$this->table.'`.'.$field; + } + } + $this->fields = $fields; + + return $this; + } + /** * Take approproate action after successfull submit * @@ -2303,7 +2357,7 @@ class e_admin_ui extends e_admin_controller_ui { $data[$key] = e107::getInstance()->ipEncode($data[$key]); } - var_dump($data[$key]); + break; //more to come } } @@ -2314,6 +2368,15 @@ class e_admin_ui extends e_admin_controller_ui $searchQry = array(); $request = $this->getRequest(); $tp = e107::getParser(); + $tablePath = '`#'.$this->table.'`.'; + $tableFrom = '`#'.$this->table.'`'; + $tableSFields = '`#'.$this->table.'`.*'; + if($this->tableAlias) + { + $tablePath = $this->tableAlias.'.'; + $tableFrom = '`#'.$this->table.'` AS '.$this->tableAlias; + $tableSFields = ''.$this->tableAlias.'.*'; + } $searchQuery = $tp->toDB($request->getQuery('searchquery', '')); list($filterField, $filterValue) = $tp->toDB(explode('__', $request->getQuery('filter_options', ''))); @@ -2321,49 +2384,45 @@ class e_admin_ui extends e_admin_controller_ui // TODO - we have var types in current model, use them! if($filterField && $filterValue !== '' && isset($this->fields[$filterField])) { - $ftable = vartrue($this->fields[$filterField]['table'], $this->getTableName()); - $searchQry[] = "`#{$ftable}`.`$filterField` = '".$filterValue."'"; + $searchQry[] = $this->fields[$filterField]['__tableField']." = '".$filterValue."'"; } $filter = array(); foreach($this->fields as $key=>$var) { - $ftable = vartrue($var['table'], $this->getTableName()); if(($var['type'] == 'text' || $var['type'] == 'method') && $searchQuery) { - $filter[] = "(`#{$ftable}`.`".$key."` REGEXP ('".$searchQuery."'))"; + //$ftable = vartrue($var['alias'], '#'.$this->getTableName()); + $filter[] = $var['__tableField']."` REGEXP ('".$searchQuery."'))"; } } - - - - //$qry = $this->listQry; - // We dont need list qry anymore! + $jwhere = array(); $joins = array(); if($this->tableJoin) { - $qry = "SELECT `#".$this->getTableName()."`.*"; + $qry = "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields; foreach ($this->tableJoin as $jtable => $tparams) { // Select fields $fields = vartrue($tparams['fields']); if('*' === $fields) { - $qry .= ", `#{$jtable}`.*"; + $qry .= ", {$tparams['__tablePath']}*"; } else { $fields = array_map('trim', explode(',', $fields)); foreach ($fields as $field) { - $qry .= ", `#{$jtable}`.`{$field}`"; + $qry .= ", {$tparams['__tablePath']}`{$field}`"; } } + // Prepare Joins $joins[] = " - ".vartrue($tparams['joinType'], 'LEFT JOIN')." `#{$jtable}` ON `#".vartrue($tparams['leftTable'], $this->getTableName())."`.`".vartrue($tparams['leftField'])."` = `#{$jtable}`.`".vartrue($tparams['rightField'])."`".(vartrue($tparams['whereJoin']) ? ' '.$tparams['whereJoin'] : ''); + ".vartrue($tparams['joinType'], 'LEFT JOIN')." {$tparams['__tableFrom']} ON ".(vartrue($tparams['leftTable']) ? $tparams['leftTable'].'.' : $tablePath)."`".vartrue($tparams['leftField'])."` = {$tparams['__tablePath']}`".vartrue($tparams['rightField'])."`".(vartrue($tparams['whereJoin']) ? ' '.$tparams['whereJoin'] : ''); // Prepare Where if(vartrue($tparams['where'])) @@ -2373,7 +2432,7 @@ class e_admin_ui extends e_admin_controller_ui } //From - $qry .= " FROM `#".$this->getTableName()."`"; + $qry .= " FROM ".$tableFrom; // Joins if(count($joins) > 0) @@ -2383,7 +2442,7 @@ class e_admin_ui extends e_admin_controller_ui } else { - $qry = "SELECT `#".$this->getTableName()."`.* FROM `#".$this->getTableName()."`"; + $qry = $this->listQry ? $this->listQry : "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields." FROM ".$tableFrom; } // join where @@ -2406,9 +2465,8 @@ class e_admin_ui extends e_admin_controller_ui $orderField = $request->getQuery('field', $this->getPrimaryName()); if(isset($this->fields[$orderField])) { - $ftable = vartrue($this->fields[$orderField]['table'], $this->getTableName()); // no need of sanitize - it's found in field array - $qry .= ' ORDER BY `#'.$ftable.'`.`'.$orderField.'` '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC'); + $qry .= ' ORDER BY '.$this->fields[$orderField]['__tableField'].' '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC'); } if($this->getPerPage()) @@ -2417,6 +2475,7 @@ class e_admin_ui extends e_admin_controller_ui //$startfrom = ($from-1) * intval($this->getPerPage()); $qry .= ' LIMIT '.$from.', '.intval($this->getPerPage()); } + return $qry; } @@ -2446,9 +2505,16 @@ class e_admin_ui extends e_admin_controller_ui return $this->pluginTitle; } - public function getTableName() + public function getTableName($alias = false, $prefix = false) { - return $this->table; + if($alias && $this->tableAlias) return $this->tableAlias; + return ($prefix ? '#.' : '').$this->table; + } + + public function getJoinTable($alias = false, $prefix = false) + { + if($alias && $this->tableAlias) return $this->tableAlias; + return ($prefix ? '#.' : '').$this->table; } public function getBatchDelete() @@ -2568,11 +2634,10 @@ class e_admin_ui extends e_admin_controller_ui $this->dataFields = array(); foreach ($this->fields as $key => $att) { - if(null === $att['type'] || vartrue($att['noedit']) || !vartrue($att['data'])) + if(null !== $att['type'] && !vartrue($att['noedit'])) { - continue; + $this->dataFields[$key] = vartrue($att['data'], 'str'); } - $this->dataFields[$key] = $att['data']; } } // TODO - do it in one loop, or better - separate method(s) -> convertFields(validate), convertFields(data),... @@ -2589,10 +2654,10 @@ class e_admin_ui extends e_admin_controller_ui { $this->validationRules[$key] = array((true === $att['validate'] ? 'required' : $att['validate']), varset($att['rule']), $att['title'], varset($att['error'], $att['help'])); } - elseif(vartrue($att['check'])) + /*elseif(vartrue($att['check'])) could go? { $this->checkRules[$key] = array($att['check'], varset($att['rule']), $att['title'], varset($att['error'], $att['help'])); - } + }*/ } } @@ -2681,7 +2746,8 @@ class e_admin_form_ui extends e_form // protect current methods from conflict. $this->preventConflict(); - + // user constructor + $this->init(); } protected function preventConflict() @@ -2930,7 +2996,8 @@ class e_admin_form_ui extends e_form case 'method': $method = $key; - $list = call_user_func_array(array($this, $method), array('', $type)); + $list = call_user_func_array(array($this, $method), array('', $type, $parms)); + if(is_array($list)) { //check for single option @@ -3209,17 +3276,18 @@ class e_admin_ui_dummy extends e_form * 1. move abstract peaces of code to the proper classes * 2. remove duplicated code (e_form & e_admin_form_ui), refactoring * 3. make JS Manager handle Styles (.css files and inline CSS) - * 4. e_form is missing some methods used in e_admin_form_ui - * 5. date convert needs string-to-datestamp auto parsing, strptime() is the solution but needs support for + * 4. [DONE] e_form is missing some methods used in e_admin_form_ui + * 5. [DONE] date convert needs string-to-datestamp auto parsing, strptime() is the solution but needs support for * Windows and PHP < 5.1.0 - build custom strptime() function (php_compatibility_handler.php) on this - * http://sauron.lionel.free.fr/?page=php_lib_strptime (bad license so no copy/paste is allowed!) * 6. [DONE - read/writeParms introduced ] $fields[parms] mess - fix it, separate list/edit mode parms somehow * 7. clean up/document all object vars (e_admin_ui, e_admin_dispatcher) - * 8. clean up/document all parameters (get/setParm()) in controller and model classes + * 8. [DONE hopefully] clean up/document all parameters (get/setParm()) in controller and model classes * 9. [DONE] 'ip' field type - convert to human readable format while showing/editing record * 10. draggable ordering (list view) * 11. realtime search filter (typing text) - like downloads currently * 12. autosubmit when 'filter' dropdown is changed (quick fix?) * 13. tablerender captions - * 14. [ALMOST - see Edit/CreateHeader() comments] textareas auto-height + * 14. [DONE] textareas auto-height + * 15. [DONE] multi JOIN table support (optional), aliases */ \ No newline at end of file diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index 4ffaf93ee..43eada510 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -7,8 +7,8 @@ * GNU General Public License (http://gnu.org). * * $Source: /cvs_backup/e107_0.8/e107_handlers/date_handler.php,v $ - * $Revision: 1.10 $ - * $Date: 2009-11-04 17:29:26 $ + * $Revision: 1.11 $ + * $Date: 2009-11-10 19:13:06 $ * $Author: secretr $ * */ @@ -61,10 +61,48 @@ class convert return strftime($mask, $datestamp); } - function toTime($date_string, $mask = '') + /** + * Convert date string back to integer (unix timestamp) + * NOTE: after some tests, strptime (compat mode) is adding +1 sec. after parsing to time, investigate! + * + * @param object $date_string + * @param object $mask [optional] + * @return + */ + function toTime($date_string, $mask = 'input') { - //TODO - convert string to datestamp, coming soon - return time(); + switch($mask) + { + case 'long': + $mask = e107::getPref('longdate'); + break; + + case 'short': + $mask = e107::getPref('shortdate'); + break; + + case 'input': //New - use inputdate as mask; FIXME - add inputdate to Date site prefs + $mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M:%S'); + break; + } + + // see php compat handler + $tdata = strptime($date_string, $mask); + if(empty($tdata)) + { + return null; + } + $unxTimestamp = mktime( + $tdata['tm_hour'], + $tdata['tm_min'], + $tdata['tm_sec'], + $tdata['tm_mon'] + 1, + $tdata['tm_mday'], + $tdata['tm_year'] + 1900 + ); + + //var_dump($tdata, $date_string, $this->convert_date($unxTimestamp, $mask), $unxTimestamp); + return $unxTimestamp; } function computeLapse($older_date, $newer_date = FALSE, $mode = FALSE, $show_secs = TRUE, $format = 'long') diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 26ac4f1b5..e67ef77d5 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,8 +9,8 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.75 $ - * $Date: 2009-11-09 16:54:29 $ + * $Revision: 1.76 $ + * $Date: 2009-11-10 19:13:06 $ * $Author: secretr $ * */ @@ -166,6 +166,7 @@ class e_form if ($datestamp) { $cal_attrib['value'] = e107::getDateConvert()->convert_date($datestamp, 'input'); //date("d/m/Y H:i:s", $datestamp); + // var_dump('date picker', $datestamp, $cal_attrib['value'], e107::getDateConvert()->toTime($cal_attrib['value']), e107::getDateConvert()->convert_date(e107::getDateConvert()->toTime($cal_attrib['value']), 'input')); } //JS manager to send JS/CSS to header if possible, if not - footer e107::getJs()// FIXME - no CSS support yet!!! ->tryHeaderFile($cal->calendar_theme_file) @@ -177,16 +178,16 @@ class e_form } /** - * UNDER CONSTRUCTION!!! + * User auto-complete search * - * @param object $name - * @param object $id_fld - * @param object $default_name - * @param object $default_id - * @param object $options [optional] + * @param string $name_fld field name for user name + * @param string $id_fld field name for user id + * @param string $default_name default user name value + * @param integer $default_id default user id + * @param array|string $options [optional] 'readonly' (make field read only), 'name' (db field name, default user_name) * @return */ - function userpicker($name, $id_fld, $default_name, $default_id, $options = array()) + function userpicker($name_fld, $id_fld, $default_name, $default_id, $options = array()) { if(!is_array($options)) parse_str($options, $options); @@ -201,7 +202,7 @@ class e_form //'.$this->text($id_fld, $default_id, 10, array('id' => false, 'readonly'=>true, 'class'=>'tbox number')).' $ret = '
- '.$this->text($name, $default_name, 150, array('id' => false, 'readonly' => vartrue($options['readonly']) ? true : false)).' + '.$this->text($name_fld, $default_name, 150, array('id' => false, 'readonly' => vartrue($options['readonly']) ? true : false)).' '.$this->hidden($id_fld, $default_id, array('id' => false)).' '.$reset.'