// // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation; either version 2 of the License, or // // (at your option) any later version. // // // // You may not change or alter any portion of this comment or credits // // of supporting developers from this source code or any supporting // // source code which is considered copyrighted (c) material of the // // original comment or credit authors. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // // Author: Raul Recio (AKA UNFOR) // // Project: The XOOPS Project // // ------------------------------------------------------------------------- // include '../../../include/cp_header.php'; function partnersAdmin() { $xoopsDB =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); xoops_cp_header(); echo "

"._MD_PARTNERADMIN."

"; $result = $xoopsDB->query("SELECT id, hits, url, weight, image, title, description, status FROM ".$xoopsDB->prefix("partners")." ORDER BY status DESC, weight ASC, title DESC"); $class = 'even'; while (list($id, $hits, $url, $weight, $image, $title, $description, $status) = $xoopsDB->fetchrow($result)) { $url = formatURL($myts->makeTboxData4Show($url)); $image = formatURL($myts->makeTboxData4Show($image)); $title = $myts->makeTboxData4Show($title); $description = $myts->makeTboxData4Show($description); $imageInfo = @getimagesize($image); $imageWidth = $imageInfo[0]; $imageHeight = $imageInfo[1]; $check1 = ""; $check2 = ""; if( $status == 1){ $check1 = "selected='selected'"; }else{ $check2 = "selected='selected'"; } if( $imageWidth >= 110 or $imageHeight >= 50 ){ $errorMsg = "
"._MD_IMAGE_ERROR; } else { $errorMsg = ""; } echo ""; $class = ($class == 'odd') ? 'even' : 'odd'; } echo "
" ._MD_TITLE." " ._MD_IMAGE." " ._MD_DESCRIPTION." " ._MD_ACTIVE." " ._MD_WEIGHT." " ._MD_HITS."  
".$title." "; if ( !empty($image) ) { echo "".$title."".$errorMsg; } echo "".$description." "; echo ""; echo "".$hits." "._MD_EDIT."
--
"._MD_DELETE."
"; xoops_cp_footer(); } function reorderPartners($weight,$status) { $xoopsDB =& Database::getInstance(); foreach ($weight as $id=>$order) { if ( isset($id) && is_numeric($id) && isset($order) ) { if ( !is_numeric($order) or empty($order)) { $order = 0; } $xoopsDB->query("UPDATE ".$xoopsDB->prefix("partners")." SET weight='$order', status='$status[$id]' WHERE id=$id"); } } redirect_header("./index.php", 1, _MD_UPDATED); exit(); } function reorderAutoPartners() { $xoopsDB =& Database::getInstance(); $weight = 0; $result = $xoopsDB->query("SELECT id FROM ".$xoopsDB->prefix("partners")." ORDER BY weight ASC"); while (list($id) = $xoopsDB->fetchrow($result)) { $weight++; $xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("partners")." SET weight='$weight' WHERE id=$id"); } redirect_header("./index.php", 1, _MD_UPDATED); exit(); } function partnersAdminAdd() { $xoopsDB =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); xoops_cp_header(); echo "

"._MD_PARTNERADMIN."

"; include XOOPS_ROOT_PATH."/class/xoopsformloader.php"; $form = new XoopsThemeForm(_MD_ADDPARTNER, "addform", "index.php", "post", true); $formweight = new XoopsFormText(_MD_WEIGHT, "weight", 3, 10, 0); $formimage = new XoopsFormText(_MD_IMAGE, "image", 50, 150, 'http://'); $formurl = new XoopsFormText(_MD_URL, "url", 50, 150, 'http://'); $formtitle = new XoopsFormText(_MD_TITLE, "title", 50, 50); $formdesc = new XoopsFormTextArea(_MD_DESCRIPTION, "description","", 10, "60"); $formstat = new XoopsFormSelect(_MD_STATUS, "status"); $formstat->addOption("1", _MD_ACTIVE); $formstat->addOption("0", _MD_INACTIVE); $op_hidden = new XoopsFormHidden("op", "addPartner"); $submit_button = new XoopsFormButton("", "submir", _MD_ADDPARTNER, "submit"); $form->addElement($formweight); $form->addElement($formimage); $form->addElement($formurl, true); $form->addElement($formtitle, true); $form->addElement($formdesc, true); $form->addElement($formstat); $form->addElement($op_hidden); $form->addElement($submit_button); $form->display(); xoops_cp_footer(); } function addPartner($weight, $url, $image, $title, $description, $status) { $xoopsDB =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $title = isset($title) ? trim($title) : ''; $image = isset($image) ? trim($image) : ''; $url = isset($url) ? trim($url) : ''; $description = isset($description) ? trim($description) : ''; if ($title == '' || $url == '' || $description == '') { redirect_header("index.php", 1, _MD_BESURE); exit(); } $url = $myts->makeTboxData4Save(formatURL($url)); $image = $myts->makeTboxData4Save(formatURL($image)); $title = $myts->makeTboxData4Save($title); $description = $myts->makeTboxData4Save($description); $image_info = @getimagesize($image); $status = isset($status) ? intval($status) : 0; $type = $image_info[2]; /* if ($type == 0) { redirect_header("index.php", 1, _MD_NOEXITS); exit(); } */ $sql = "INSERT INTO ".$xoopsDB->prefix("partners")." VALUES (NULL, ".intval($weight).", 0, '$url', '$image', '$title', '$description', $status)"; if ($GLOBALS['xoopsSecurity']->check() && $xoopsDB->query($sql)) { redirect_header("index.php", 1, _MD_UPDATED); } else { redirect_header("index.php", 1, _MD_NOTUPDATED."
".implode('
', $GLOBALS['xoopsSecurity']->getErrors())); } exit(); } function editPartner($id) { $xoopsDB =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); xoops_cp_header(); echo "

"._MD_PARTNERADMIN."

"; $result = $xoopsDB->query("SELECT weight, hits, url, image, title, description, status FROM ".$xoopsDB->prefix("partners")." WHERE id=$id"); list($weight, $hits, $url, $image, $title, $description, $status) = $xoopsDB->fetchrow($result); $url = $myts->makeTboxData4Edit($url); $image = $myts->makeTboxData4Edit($image); $title = $myts->makeTboxData4Edit($title); $description = $myts->makeTboxData4Edit($description); include XOOPS_ROOT_PATH."/class/xoopsformloader.php"; $form = new XoopsThemeForm(_MD_EDITPARTNER, "editform", "index.php", "post", true); $formweight = new XoopsFormText(_MD_WEIGHT, "weight", 3, 10, $weight); $formhits = new XoopsFormText(_MD_HITS, "hits", 3, 10, $hits); $formimage = new XoopsFormText(_MD_IMAGE, "image", 50, 150, $image); $formurl = new XoopsFormText(_MD_URL, "url", 50, 150, $url); $formtitle = new XoopsFormText(_MD_TITLE, "title", 50, 50, $title); $formdesc = new XoopsFormTextArea(_MD_DESCRIPTION, "description", $description, 10, "100%"); $formstat = new XoopsFormSelect(_MD_STATUS, "status", $status); $formstat->addOption("1", _MD_ACTIVE); $formstat->addOption("0", _MD_INACTIVE); $id_hidden = new XoopsFormHidden("id", $id); $op_hidden = new XoopsFormHidden("op", "updatePartner"); $submit_button = new XoopsFormButton("", "submit", _MD_EDITPARTNER, "submit"); $form->addElement($formweight); $form->addElement($formhits); $form->addElement($formimage); $form->addElement($formurl, true); $form->addElement($formtitle, true); $form->addElement($formdesc, true); $form->addElement($formstat); $form->addElement($id_hidden); $form->addElement($op_hidden); $form->addElement($submit_button); $form->display(); xoops_cp_footer(); } function updatePartner($id, $weight, $hits, $url, $image, $title, $description, $status) { $xoopsDB =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $title = isset($title) ? trim($title) : ''; $image = isset($image) ? trim($image) : ''; $url = isset($url) ? trim($url) : ''; $description = isset($description) ? trim($description) : ''; $id = intval($id); $status = isset($status) ? intval($status) : 0; if ($title == '' || $url == '' || empty($id) || $description == '') { redirect_header("index.php?op=edit_partner&id=$id", 1, _MD_BESURE); exit(); } $url = $myts->makeTboxData4Save(formatURL($url)); $image = $myts->makeTboxData4Save(formatURL($image)); $title = $myts->makeTboxData4Save($title); $description = $myts->makeTboxData4Save($description); $image_info = @getimagesize($image); $type = $image_info[2]; if ($type == 0) { redirect_header("index.php?op=edit_partner&id=$id", 1, _MD_NOEXITS); exit(); } if ($GLOBALS['xoopsSecurity']->check() && $xoopsDB->query("UPDATE ".$xoopsDB->prefix("partners")." SET hits=".intval($hits).", weight=".intval($weight).", url='$url', image='$image', title='$title', description='$description', status=$status WHERE id=$id")) { redirect_header("index.php", 1, _MD_UPDATED); } else { redirect_header("index.php", 1, _MD_NOTUPDATED."
".implode('
', $GLOBALS['xoopsSecurity']->getErrors())); } exit(); } function delPartner($id, $del=0) { $xoopsDB =& Database::getInstance(); if ( $del == 1 ) { $sql = sprintf("DELETE FROM %s WHERE id = %u", $xoopsDB->prefix("partners"), $id); if ( $xoopsDB->query($sql) ) { redirect_header("index.php", 1, _MD_UPDATED); } else { redirect_header("index.php", 1, _MD_NOTUPDATED); } exit(); } else { xoops_cp_header(); echo "

"._MD_PARTNERADMIN."

"; xoops_confirm(array('op' => 'delPartner', 'id' => $id, 'del' => 1), 'index.php', _MD_SUREDELETE); xoops_cp_footer(); } } $op = ''; foreach ($HTTP_POST_VARS as $k => $v) { ${$k} = $v; } if (isset($HTTP_GET_VARS['op'])) { $op = $HTTP_GET_VARS['op']; if (isset($HTTP_GET_VARS['id'])) { $id = intval($HTTP_GET_VARS['id']); } } switch ($op) { case "partnersAdminAdd": partnersAdminAdd(); break; case "updatePartner": updatePartner($id, $weight, $hits, $url, $image, $title, $description, $status); break; case "addPartner": addPartner($weight, $url, $image, $title, $description, $status); break; case "delPartner": delPartner($id, $del); break; case "editPartner": editPartner($id); break; case "reorderPartners": reorderPartners($weight,$status); break; case "reorderAutoPartners": reorderAutoPartners(); break; default: partnersAdmin(); break; } ?>