diff --git a/e107_admin/db_verify.php b/e107_admin/db_verify.php index c188c8b7e..c85ec8810 100644 --- a/e107_admin/db_verify.php +++ b/e107_admin/db_verify.php @@ -9,8 +9,8 @@ * Administration - DB Verify * * $Source: /cvs_backup/e107_0.8/e107_admin/db_verify.php,v $ - * $Revision: 1.7 $ - * $Date: 2009-08-28 16:49:42 $ + * $Revision: 1.8 $ + * $Date: 2009-09-10 19:15:43 $ * $Author: secretr $ * */ @@ -616,31 +616,33 @@ exit; // -------------------------------------------------------------- function fix_form($table,$field, $newvalue,$mode,$after =''){ global $frm; - - if(stristr($field, 'KEY ') !== FALSE) - { - $field = chop(str_replace('KEY ','',$field)); - $mode = ($mode == 'drop') ? 'indexdrop' : 'index'; - $search = array('(', ')'); - $newvalue = str_replace($search,'',$newvalue); - $after = ''; - } - if($mode == 'index' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) - { - $mode = 'indexalt'; - } - elseif($mode == 'indexdrop' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) - { - $field = trim(str_replace(array('FULLTEXT ', 'UNIQUE '), '', $field)); - } - if($mode == 'create') { $newvalue = implode("\n",$newvalue); } + else + { + if(stristr($field, 'KEY ') !== FALSE) + { + $field = chop(str_replace('KEY ','',$field)); + $mode = ($mode == 'drop') ? 'indexdrop' : 'index'; + $search = array('(', ')'); + $newvalue = str_replace($search,'',$newvalue); + $after = ''; + } + + if($mode == 'index' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) + { + $mode = 'indexalt'; + } + elseif($mode == 'indexdrop' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) + { + $field = trim(str_replace(array('FULLTEXT ', 'UNIQUE '), '', $field)); + } + $field = trim($field, '`'); + } - $field = trim($field, '`'); $text .= $frm->checkbox("fix_active[$field][]", 1, false, array('id'=>false)); $text .= "\n"; $text .= "\n"; diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 2d8936d5c..1b4e8502b 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -9,9 +9,9 @@ * News Administration * * $Source: /cvs_backup/e107_0.8/e107_admin/newspost.php,v $ - * $Revision: 1.49 $ - * $Date: 2009-08-28 16:11:01 $ - * $Author: marj_nl_fr $ + * $Revision: 1.50 $ + * $Date: 2009-09-10 19:15:43 $ + * $Author: secretr $ */ require_once("../class2.php"); @@ -166,8 +166,10 @@ class admin_newspost var $_sort_order; var $_sort_link; var $fieldpref; + + public $error = false; - function admin_newspost($qry, $pstobj) + function __construct($qry, $pstobj) { global $user_pref; $this->parseRequest($qry); @@ -218,16 +220,46 @@ class admin_newspost { return $this->_request[0]; } + + /** + * @param string $action + * @return admin_newspost + */ + function setAction($action) + { + $this->_request[0] = $action; + return $this; + } function getSubAction() { return $this->_request[1]; } + + /** + * @param string $action + * @return admin_newspost + */ + function setSubAction($action) + { + $this->_request[1] = $action; + return $this; + } function getId() { return $this->_request[2]; } + + /** + * @param integer $id + * @return admin_newspost + */ + function setId($id) + { + $this->_request[2] = intval($id); + return $this; + } function getSortOrder() { @@ -261,6 +293,8 @@ class admin_newspost function observer() { + e107::getDb()->db_Mark_Time('News Administration'); + //Required on create & savepreset action triggers if(isset($_POST['news_userclass']) && is_array($_POST['news_userclass'])) { @@ -485,11 +519,26 @@ class admin_newspost function _observe_create_category() { - global $admin_log; - if ($_POST['category_name']) + + //FIXME - lan, e_model based news administration model + $this->error = false; + if(empty($_POST['category_name'])) { - $e107 = &e107::getInstance(); - if (empty($_POST['category_button'])) + $this->show_message('Validation Error: Missing Category name', E_MESSAGE_ERROR); + $this->error = true; + } + + if(!empty($_POST['news_rewrite_string']) && preg_match('#[^\w\pL\-]#u', $_POST['news_rewrite_string'])) + { + $this->show_message('Validation Error: Bad value for Category friendly URL', E_MESSAGE_ERROR); + $this->error = true; + } + + if (!$this->error) + { + $inserta = array(); + /* Why? + if (empty($_POST['category_icon'])) { $handle = opendir(e_IMAGE."icons"); while ($file = readdir($handle)) @@ -499,31 +548,204 @@ class admin_newspost } } closedir($handle); - $_POST['category_button'] = $iconlist[0]; + $inserta['category_icon'] = $iconlist[0]; } else { - $_POST['category_button'] = $e107->tp->toDB($_POST['category_button']); + $inserta['category_icon'] = e107::getParser()->toDB($_POST['category_icon']); + }*/ + + $inserta['data']['category_icon'] = $_POST['category_icon']; + $inserta['_FIELD_TYPES']['category_icon'] = 'todb'; + + $inserta['data']['category_name'] = $_POST['category_name']; + $inserta['_FIELD_TYPES']['category_name'] = 'todb'; + + $inserta['data']['category_meta_description'] = strip_tags($_POST['category_meta_description']); + $inserta['_FIELD_TYPES']['category_meta_description'] = 'str'; + + $inserta['data']['category_meta_keywords'] = $_POST['category_meta_keywords']; + $inserta['_FIELD_TYPES']['category_meta_keywords'] = 'str'; + + $inserta['data']['category_manager'] = $_POST['category_manager']; + $inserta['_FIELD_TYPES']['category_manager'] = 'int'; + + if(isset($_POST['category_order'])) $_POST['category_order'] = 0; + $inserta['data']['category_order'] = $_POST['category_order']; + $inserta['_FIELD_TYPES']['category_order'] = 'int'; + + //e107::getDb()->db_Insert('news_category', "'0', '{$_POST['category_name']}', '{$_POST['category_icon']}'"); + $id = e107::getDb()->db_Insert('news_category', $inserta); + if($id) + { + //Manage rewrite + if(!empty($_POST['news_rewrite_string'])) + { + $rinserta = array(); + $rinserta['data']['news_rewrite_source'] = $id; + $rinserta['_FIELD_TYPES']['news_rewrite_source'] = 'int'; + + $rinserta['data']['news_rewrite_string'] = $_POST['news_rewrite_string']; + $rinserta['_FIELD_TYPES']['news_rewrite_string'] = 'todb'; + + $rinserta['data']['news_rewrite_type'] = 2; + $rinserta['_FIELD_TYPES']['news_rewrite_type'] = 'int'; + + e107::getDb()->db_Insert('news_rewrite', $rinserta); + if(e107::getDb()->mySQLlastErrNum) + { + $this->error = true; + $this->show_message('Category friendly URL sting related problem detected!', E_MESSAGE_ERROR); + if(1052 == e107::getDb()->mySQLlastErrNum) + { + $this->show_message('Category friendly URL should be unique! ', E_MESSAGE_ERROR); + } + $this->show_message('mySQL error #'.e107::getDb()->mySQLlastErrNum.': '.e107::getDb()->mySQLlastErrText, E_MESSAGE_DEBUG); + return; + } + } + else + { + e107::getDb()->db_Delete('news_rewrite', 'news_rewrite_source='.$id); + } + + //admin log now supports DB array and method chaining + //$_POST['category_name'].', '.$_POST['category_icon'] + unset($inserta['data']['category_meta_description']); //too long for logging? + e107::getAdminLog() + ->log_event('NEWS_04', $inserta, E_LOG_INFORMATIVE, '') + ->log_event('NEWS_04', $rinserta, E_LOG_INFORMATIVE, ''); //XXX fix lan for SEF string log or just don't log it? + + $this->show_message(NWSLAN_35, E_MESSAGE_SUCCESS); + $this->clear_cache(); + } + else + { + //debug + error message + if(e107::getDb()->mySQLlastErrNum) + { + $this->error = true; + $this->show_message('mySQL Error detected!', E_MESSAGE_ERROR); + eMessage::getInstance()->addS('mySQL error #'.e107::getDb()->mySQLlastErrNum.': '.e107::getDb()->mySQLlastErrText, E_MESSAGE_DEBUG); + } } - $_POST['category_name'] = $e107->tp->toDB($_POST['category_name']); - $e107->sql->db_Insert('news_category', "'0', '{$_POST['category_name']}', '{$_POST['category_button']}'"); - $admin_log->log_event('NEWS_04',$_POST['category_name'].', '.$_POST['category_button'],E_LOG_INFORMATIVE,''); - $this->show_message(NWSLAN_35, E_MESSAGE_SUCCESS); - $this->clear_cache(); } } + function _observe_update_category() - { - global $admin_log; - if ($_POST['category_name']) + { + $this->setId(intval($_POST['category_id'])); + + if(!$this->getId()) { - $e107 = &e107::getInstance(); - $category_button = $e107->tp->toDB(($_POST['category_button'] ? $_POST['category_button'] : "")); - $_POST['category_name'] = $e107->tp->toDB($_POST['category_name']); - $e107->sql->db_Update("news_category", "category_name='".$_POST['category_name']."', category_icon='".$category_button."' WHERE category_id=".intval($_POST['category_id'])); - $admin_log->log_event('NEWS_05',intval($_POST['category_id']).':'.$_POST['category_name'].', '.$category_button,E_LOG_INFORMATIVE,''); - $this->show_message(NWSLAN_36, E_MESSAGE_SUCCESS); - $this->clear_cache(); + return; + } + + //FIXME - lan, e_model based news administration model + $this->error = false; + if(empty($_POST['category_name'])) + { + $this->show_message('Validation Error: Missing Category name', E_MESSAGE_ERROR); + $this->error = true; + } + + if(!empty($_POST['news_rewrite_string']) && preg_match('#[^\w\pL\-]#u', $_POST['news_rewrite_string'])) + { + $this->show_message('Validation Error: Bad value for Category friendly URL', E_MESSAGE_ERROR); + $this->error = true; + } + + if (!$this->error) + { + $updatea = array(); + $updatea['data']['category_icon'] = $_POST['category_icon']; + $updatea['_FIELD_TYPES']['category_icon'] = 'todb'; + + $updatea['data']['category_name'] = $_POST['category_name']; + $updatea['_FIELD_TYPES']['category_name'] = 'todb'; + + $updatea['data']['category_meta_description'] = strip_tags($_POST['category_meta_description']); + $updatea['_FIELD_TYPES']['category_meta_description'] = 'str'; + + $updatea['data']['category_meta_keywords'] = $_POST['category_meta_keywords']; + $updatea['_FIELD_TYPES']['category_meta_keywords'] = 'str'; + + $updatea['data']['category_manager'] = $_POST['category_manager']; + $updatea['_FIELD_TYPES']['category_manager'] = 'int'; + + if(isset($_POST['category_order'])) $_POST['category_order'] = 0; + $updatea['data']['category_order'] = $_POST['category_order']; + $updatea['_FIELD_TYPES']['category_order'] = 'int'; + + $updatea['WHERE'] = 'category_id='.$this->getId(); + + if(e107::getDb()->db_Update("news_category", $updatea) || !e107::getDb()->mySQLlastErrNum) + { + //Manage rewrite + if(!empty($_POST['news_rewrite_string'])) + { + $inserta = array(); + + $inserta['data']['news_rewrite_id'] = isset($_POST['news_rewrite_id']) ? $_POST['news_rewrite_id'] : 0; + $inserta['_FIELD_TYPES']['news_rewrite_id'] = 'int'; + + $inserta['data']['news_rewrite_source'] = $this->getId(); + $inserta['_FIELD_TYPES']['news_rewrite_source'] = 'int'; + + $inserta['data']['news_rewrite_string'] = $_POST['news_rewrite_string']; + $inserta['_FIELD_TYPES']['news_rewrite_string'] = 'todb'; + + $inserta['data']['news_rewrite_type'] = 2; + $inserta['_FIELD_TYPES']['news_rewrite_type'] = 'int'; + + $tmp = e107::getDb()->db_Replace('news_rewrite', $inserta); + if(e107::getDb()->mySQLlastErrNum) + { + $this->error = true; + $this->setSubAction('edit'); + $this->show_message('Category friendly URL sting related problem detected!', E_MESSAGE_ERROR); + if(1052 == e107::getDb()->mySQLlastErrNum) + { + $this->show_message('Category friendly URL should be unique! ', E_MESSAGE_ERROR); + } + $this->show_message('mySQL error #'.e107::getDb()->mySQLlastErrNum.': '.e107::getDb()->mySQLlastErrText, E_MESSAGE_DEBUG); + return; + } + + if(!$tmp) $this->show_message(LAN_NO_CHANGE); + else $this->show_message(NWSLAN_36, E_MESSAGE_SUCCESS); + return; + } + else + { + e107::getDb()->db_Delete('news_rewrite', 'news_rewrite_source='.$this->getId()); + } + + //admin log now supports DB array and method chaining + //$_POST['category_name'].', '.$_POST['category_icon'] + unset($updatea['data']['category_meta_description']); //too long for logging? + e107::getAdminLog() + ->log_event('NEWS_04', $updatea, E_LOG_INFORMATIVE, '') + ->log_event('NEWS_04', $rinserta, E_LOG_INFORMATIVE, ''); //XXX fix lan for SEF string log or just don't log it? + + $this->show_message(NWSLAN_36, E_MESSAGE_SUCCESS); + $this->clear_cache(); + $this->setId(0); + } + else + { + //debug + error message + //if(e107::getDb()->mySQLlastErrNum) + //{ + $this->error = true; + $this->setSubAction('edit'); + $this->show_message('mySQL Error detected!', E_MESSAGE_ERROR); + $this->show_message('#'.e107::getDb()->mySQLlastErrNum.': '.e107::getDb()->mySQLlastErrText, E_MESSAGE_DEBUG); + return; + //} + //$this->show_message(LAN_NO_CHANGE); + //$this->setId(0); + } } } @@ -1373,12 +1595,21 @@ class admin_newspost 'disabled,1' => 'create-category', 'hide' => 'create-category' )); + + $jshelper->addResponseAction('fill-form', $category); + + $category_rewrite = array(); + if ($e107->sql->db_Select("news_rewrite", "*", "news_rewrite_source=".$this->getId())) + { + $category_rewrite = $e107->sql->db_Fetch(); + $jshelper->addResponseAction('fill-form', $category_rewrite); + } //category icon alias - $category['category-button'] = $category['category_icon']; + //$category['category-button'] = $category['category_icon']; //Send the prefered response type - $jshelper->sendResponse('fill-form', $category); + $jshelper->sendResponse('fill-form'); } function show_categories() @@ -1386,17 +1617,41 @@ class admin_newspost require_once(e_HANDLER."form_handler.php"); $frm = new e_form(true); //enable inner tabindex counter - $e107 = &e107::getInstance(); + $e107 = e107::getInstance(); $category = array(); - if ($this->getSubAction() == "edit") + $category_rewrite = array(); + if ($this->getSubAction() == "edit" && !isset($_POST['update_category'])) { - if ($e107->sql->db_Select("news_category", "*", "category_id=".$this->getId())) + if (e107::getDb()->db_Select("news_category", "*", "category_id=".$this->getId())) { - $category = $e107->sql->db_Fetch(); + $category = e107::getDb()->db_Fetch(); + } + if($category && e107::getDb()->db_Select('news_rewrite', '*', 'news_rewrite_source='.$this->getId().' AND news_rewrite_type=2')) + { + $category_rewrite = e107::getDb()->db_Fetch(); + } + } + + if($this->error && (isset($_POST['update_category']) || isset($_POST['create_category']))) + { + foreach ($_POST as $k=>$v) + { + if(strpos($k, 'category_') === 0) + { + $category[$k] = e107::getParser()->post_toForm($v); + continue; + } + + if(strpos($k, 'news_rewrite_') === 0) + { + $category_rewrite[$k] = e107::getParser()->post_toForm($v); + continue; + } } } + //FIXME - lan $text = "