From: <ir...@us...> - 2012-08-02 07:28:25
|
Revision: 9977 http://xoops.svn.sourceforge.net/xoops/?rev=9977&view=rev Author: irmtfan Date: 2012-08-02 07:28:11 +0000 (Thu, 02 Aug 2012) Log Message: ----------- apply style.css customization apply input time localization remove many hardcodes in templates Modified Paths: -------------- XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev9883.txt XoopsModules/newbb/branches/irmtfan/newbb/header.php XoopsModules/newbb/branches/irmtfan/newbb/polls.php XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_index.html XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_thread.html XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_viewall.html XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_viewforum.html XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_viewpost.html XoopsModules/newbb/branches/irmtfan/newbb/templates/newbb_viewtopic.html Modified: XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev9883.txt =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev9883.txt 2012-08-02 05:24:36 UTC (rev 9976) +++ XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev9883.txt 2012-08-02 07:28:11 UTC (rev 9977) @@ -1,7 +1,27 @@ Changelog from rev.9883 +date: 2012-08-01 +================================================ +1- localization: input date localized (for other date systems like hegira) by replacing strtotime by XoopsLocal::strtotime +in newbb/polls.php + +2- customization&localization: newbb style.css is fully localized and customized and is not hard-coded anymore. +in newbb/header.php +file changes: +-- deleted newbb/templates/style.css +-- added newbb/templates/images/language/english/style.css +-- added newbb/templates/images/language/persian/style.css +priorities: +if exist in themes/YOUR_THEME/modules/newbb/images/language/YOUR_LANG/style.css take it +else if exist in themes/default/modules/newbb/images/language/YOUR_LANG/style.css take it +else if exist in modules/newbb/templates/images/language/YOUR_LANG/style.css take it +else if exist in modules/newbb/templates/images/language/english/style.css take it +else if exist in modules/newbb/templates/style.css take it (for backward compatibility) + +3- many hardcodes in newbb/templates and style.css has been removed + date: 2012-07-30 ================================================ -1- bug fix: edit not record when the reason is not filled (irmtfan) +1- bug fix: edit not displayed when the reason is not filled (irmtfan) 2- bug fix: only the last edit is recorded. (irmtfan/alfred) in newbb/class/post.php 3- bug fix: 'noapprove' permission incorrectly recorded in database. (irmtfan) @@ -12,5 +32,5 @@ in newbb/xoops_version.php 6- hardcode: some style.css color hardcodes has been removed. (irmtfan) in newbb/templates/style.css -7- feature added: text links instead of buttons. (deka98/irmtfan) -in newbb/class/icon.php , newbb/include/functions.render.php , newbb/include/plugin.php +7- feature added: text links instead of buttons. (deka87/irmtfan) +in newbb/class/icon.php , newbb/include/functions.render.php , newbb/include/plugin.php \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/header.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/header.php 2012-08-02 05:24:36 UTC (rev 9976) +++ XoopsModules/newbb/branches/irmtfan/newbb/header.php 2012-08-02 07:28:11 UTC (rev 9977) @@ -1,116 +1,140 @@ -<?php -/** - * CBB 4.0, or newbb, the forum module for XOOPS project - * - * @copyright The XOOPS Project http://xoops.sf.net - * @license http://www.fsf.org/copyleft/gpl.html GNU public license - * @author Taiwen Jiang (phppp or D.J.) <ph...@us...> - * @since 4.00 - * @version $Id$ - * @package module::newbb - */ -include_once '../../mainfile.php'; -defined('XOOPS_ROOT_PATH') or die('Restricted access'); -$xoopsLogger->startTime('newBB_Header'); - -if (!empty($xoopsModuleConfig['do_rewrite'])) { - include_once "seo_url.php"; - /* for seo */ - $toseo_url = array("index.php","viewforum.php","viewtopic.php","rss.php"); - - if(((strpos(getenv('REQUEST_URI'), '.html') === false) && !empty($xoopsModuleConfig['do_rewrite']) && (!isset($_POST) || count($_POST) <= 0))) - { - $redir = false; - if ( strpos(getenv("REQUEST_URI"),"mark_read=") == true || strpos(getenv("REQUEST_URI"),"mark=") == true) { - // Mark Forums - } else { - if ( in_array(basename(getenv('SCRIPT_NAME')),$toseo_url) ) { - //rewrite only for files - - if ( trim(getenv("SCRIPT_NAME")) != '' ) { - if ( strpos(getenv("REQUEST_URI") , "/".SEO_MODULE_NAME."/") === false ) { - $redir = true; - } else if ( getenv("QUERY_STRING") ) { - $redir = true; - } - } - } - } - - if ($redir == true) { - $s = "http://" . getenv('HTTP_HOST') . getenv("REQUEST_URI"); - $s = str_replace("/".REAL_MODULE_NAME."/","/".SEO_MODULE_NAME."/",$s); - $newurl = seo_urls('<a href="'.$s.'"></a>'); - $newurl = str_replace('<a href="','',$newurl); - $newurl = str_replace('"></a>','',$newurl); - if ( !headers_sent() ) { - header("HTTP/1.1 301 Moved Permanently"); - header("Location: $newurl"); - exit(); - } - } - } -} - -include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/include/vars.php"; - -mod_loadFunctions("user", "newbb"); -mod_loadFunctions("topic", "newbb"); - -require_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; -require_once XOOPS_ROOT_PATH."/class/module.textsanitizer.php"; -$myts = MyTextSanitizer::getInstance(); - -$menumode = 0; -$menumode_other = array(); -$menu_url = htmlSpecialChars(preg_replace("/&menumode=[^&]/", "", $_SERVER[ 'REQUEST_URI' ])); -$menu_url .= ( false === strpos($menu_url, "?") ) ? "?menumode=" : "&menumode="; -foreach ($xoopsModuleConfig["valid_menumodes"] as $key => $val) { - if ($key != $menumode) $menumode_other[] = array("title"=>$val, "link"=>$menu_url.$key); -} - - -$newbb_module_header = ''; -$newbb_module_header .= '<link rel="alternate" type="application/rss+xml" title="'.$xoopsModule->getVar("name").'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname', "n").'/rss.php" />'; -if (!empty($xoopsModuleConfig['pngforie_enabled'])) { - $newbb_module_header .= '<style type="text/css">img {behavior:url("include/pngbehavior.htc");}</style>'; -} -$newbb_module_header .= ' - <link rel="stylesheet" type="text/css" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'/templates/style.css" /> - <script type="text/javascript">var toggle_cookie="'.$forumCookie['prefix'].'G'.'";</script> - <script src="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'/include/js/newbb_toggle.js" type="text/javascript"></script> - '; - -if ($menumode == 2) { - $newbb_module_header .= ' - <link rel="stylesheet" type="text/css" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'templates/newbb_menu_hover.css" /> - <style type="text/css">body {behavior:url("include/newbb.htc");}</style> - '; -} - -if ($menumode == 1) { - $newbb_module_header .= ' - <link rel="stylesheet" type="text/css" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'templates/newbb_menu_click.css" /> - <script src="include/js/newbb_menu_click.js" type="text/javascript"></script> - '; -} - -$xoops_module_header = $newbb_module_header; // for cache hack - -if (!empty($xoopsModuleConfig["welcome_forum"]) && is_object($xoopsUser) && !$xoopsUser->getVar('posts')) { - mod_loadFunctions("welcome", "newbb"); -} - -$pollmodules = NULL; -//$module_handler = &xoops_gethandler('module'); -$xoopspoll = &$module_handler->getByDirname('xoopspoll'); -if (is_object($xoopspoll) && $xoopspoll->getVar('isactive')) { - $pollmodules = 'xoopspoll'; -} else { - //Umfrage - $xoopspoll = &$module_handler->getByDirname('umfrage'); - if (is_object($xoopspoll) && $xoopspoll->getVar('isactive')) - $pollmodules = 'umfrage'; -} -$xoopsLogger->stopTime('newBB_Header'); +<?php +/** + * CBB 4.0, or newbb, the forum module for XOOPS project + * + * @copyright The XOOPS Project http://xoops.sf.net + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @author Taiwen Jiang (phppp or D.J.) <ph...@us...> + * @since 4.00 + * @version $Id$ + * @package module::newbb + */ +include_once '../../mainfile.php'; +defined('XOOPS_ROOT_PATH') or die('Restricted access'); +$xoopsLogger->startTime('newBB_Header'); + +if (!empty($xoopsModuleConfig['do_rewrite'])) { + include_once "seo_url.php"; + /* for seo */ + $toseo_url = array("index.php","viewforum.php","viewtopic.php","rss.php"); + + if(((strpos(getenv('REQUEST_URI'), '.html') === false) && !empty($xoopsModuleConfig['do_rewrite']) && (!isset($_POST) || count($_POST) <= 0))) + { + $redir = false; + if ( strpos(getenv("REQUEST_URI"),"mark_read=") == true || strpos(getenv("REQUEST_URI"),"mark=") == true) { + // Mark Forums + } else { + if ( in_array(basename(getenv('SCRIPT_NAME')),$toseo_url) ) { + //rewrite only for files + + if ( trim(getenv("SCRIPT_NAME")) != '' ) { + if ( strpos(getenv("REQUEST_URI") , "/".SEO_MODULE_NAME."/") === false ) { + $redir = true; + } else if ( getenv("QUERY_STRING") ) { + $redir = true; + } + } + } + } + + if ($redir == true) { + $s = "http://" . getenv('HTTP_HOST') . getenv("REQUEST_URI"); + $s = str_replace("/".REAL_MODULE_NAME."/","/".SEO_MODULE_NAME."/",$s); + $newurl = seo_urls('<a href="'.$s.'"></a>'); + $newurl = str_replace('<a href="','',$newurl); + $newurl = str_replace('"></a>','',$newurl); + if ( !headers_sent() ) { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: $newurl"); + exit(); + } + } + } +} + +include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/include/vars.php"; + +mod_loadFunctions("user", "newbb"); +mod_loadFunctions("topic", "newbb"); + +require_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; +require_once XOOPS_ROOT_PATH."/class/module.textsanitizer.php"; +$myts = MyTextSanitizer::getInstance(); + +$menumode = 0; +$menumode_other = array(); +$menu_url = htmlSpecialChars(preg_replace("/&menumode=[^&]/", "", $_SERVER[ 'REQUEST_URI' ])); +$menu_url .= ( false === strpos($menu_url, "?") ) ? "?menumode=" : "&menumode="; +foreach ($xoopsModuleConfig["valid_menumodes"] as $key => $val) { + if ($key != $menumode) $menumode_other[] = array("title"=>$val, "link"=>$menu_url.$key); +} + + +$newbb_module_header = ''; +$newbb_module_header .= '<link rel="alternate" type="application/rss+xml" title="'.$xoopsModule->getVar("name").'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname', "n").'/rss.php" />'; +if (!empty($xoopsModuleConfig['pngforie_enabled'])) { + $newbb_module_header .= '<style type="text/css">img {behavior:url("include/pngbehavior.htc");}</style>'; +} +// START hacked by irmtfan to add localization/customization for newbb style.css +$dirname=$xoopsModule->getVar('dirname'); +$theme_path = "{$xoopsConfig['theme_set']}/modules/{$dirname}"; +$theme_default_path= "default/modules/{$dirname}"; +$default_path = "modules/{$dirname}/templates"; +$lang_path = "images/language/{$xoopsConfig['language']}"; + + // get from setted theme +if (is_file(XOOPS_THEME_PATH . '/'.$theme_path . '/' . $lang_path . '/style.css')) { + $rel_path=$theme_path . '/' . $lang_path; + // get from default theme +} else if (is_file(XOOPS_THEME_PATH . '/'.$theme_default_path . '/' . $lang_path . '/style.css')) { + $rel_path=$theme_default_path . '/' . $lang_path; + // get from module default path +} else if (is_file(XOOPS_ROOT_PATH. '/'.$default_path . '/' . $lang_path . '/style.css')) { + $rel_path=$default_path . '/' . $lang_path; + // if no one is found get the english from default path +} else if (is_file(XOOPS_ROOT_PATH. '/'.$default_path . '/images/language/english/style.css')) { + $rel_path=$default_path . '/images/language/english'; + // for backward compatibility - as before +} else { + $rel_path=$default_path; +} + +$newbb_module_header .= ' + <link rel="stylesheet" type="text/css" href="'.XOOPS_URL . '/' . $rel_path . '/style.css" /> + <script type="text/javascript">var toggle_cookie="'.$forumCookie['prefix'].'G'.'";</script> + <script src="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'/include/js/newbb_toggle.js" type="text/javascript"></script> + '; +// END hacked by irmtfan to add localization/customization for newbb style.css +if ($menumode == 2) { + $newbb_module_header .= ' + <link rel="stylesheet" type="text/css" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'templates/newbb_menu_hover.css" /> + <style type="text/css">body {behavior:url("include/newbb.htc");}</style> + '; +} + +if ($menumode == 1) { + $newbb_module_header .= ' + <link rel="stylesheet" type="text/css" href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname").'templates/newbb_menu_click.css" /> + <script src="include/js/newbb_menu_click.js" type="text/javascript"></script> + '; +} + +$xoops_module_header = $newbb_module_header; // for cache hack + +if (!empty($xoopsModuleConfig["welcome_forum"]) && is_object($xoopsUser) && !$xoopsUser->getVar('posts')) { + mod_loadFunctions("welcome", "newbb"); +} + +$pollmodules = NULL; +//$module_handler = &xoops_gethandler('module'); +$xoopspoll = &$module_handler->getByDirname('xoopspoll'); +if (is_object($xoopspoll) && $xoopspoll->getVar('isactive')) { + $pollmodules = 'xoopspoll'; +} else { + //Umfrage + $xoopspoll = &$module_handler->getByDirname('umfrage'); + if (is_object($xoopspoll) && $xoopspoll->getVar('isactive')) + $pollmodules = 'umfrage'; +} +$xoopsLogger->stopTime('newBB_Header'); ?> \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/polls.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/polls.php 2012-08-02 05:24:36 UTC (rev 9976) +++ XoopsModules/newbb/branches/irmtfan/newbb/polls.php 2012-08-02 07:28:11 UTC (rev 9977) @@ -1,570 +1,580 @@ -<?php -/** - * Newbb module - * - * 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. - * - * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ - * @license http://www.fsf.org/copyleft/gpl.html GNU public license - * @package newbb - * @since 4.0 - * @author Taiwen Jiang <ph...@us...> - * @version $Id: polls.php 2175 2008-09-23 14:07:03Z phppp $ - */ - - -include_once dirname(__FILE__) . "/header.php"; - -include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; -include_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; -include_once XOOPS_ROOT_PATH . "/class/xoopsblock.php"; - -if ( $pollmodules == 'xoopspoll') -{ - include XOOPS_ROOT_PATH . "/modules/xoopspoll/include/constants.php"; - include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspoll.php"; - include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspolloption.php"; - include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspolllog.php"; - include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspollrenderer.php"; -} -elseif ($pollmodules == 'umfrage') -{ - include XOOPS_ROOT_PATH."/modules/umfrage/include/constants.php"; - include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfrage.php"; - include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfrageoption.php"; - include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfragelog.php"; - include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfragerenderer.php"; -} -else -{ - redirect_header("javascript:history.go(-1);", 2, _MD_POLLMODULE_ERROR); - exit(); -} - -$op = "add"; -if (isset($_GET['op'])) $op = $_GET['op']; -if (isset($_POST['op'])) $op = $_POST['op']; -if (isset($_GET['poll_id'])) $poll_id = intval($_GET['poll_id']); -if (isset($_POST['poll_id'])) $poll_id = intval($_POST['poll_id']); -if (isset($_GET['topic_id'])) $topic_id = intval($_GET['topic_id']); -if (isset($_POST['topic_id'])) $topic_id = intval($_POST['topic_id']); - -if (!isset($module_handler)) $module_handler =& xoops_gethandler('module'); -$xoopspoll =& $module_handler->getByDirname($pollmodules); -if (!is_object($xoopspoll) || !$xoopspoll->getVar('isactive')) { - redirect_header("javascript:history.go(-1);", 2, _MD_POLLMODULE_ERROR); - exit(); -} - -include XOOPS_ROOT_PATH . "/header.php"; - -$topic_handler =& xoops_getmodulehandler('topic', 'newbb'); -$topic_obj =& $topic_handler->get($topic_id); -$forum = $topic_obj->getVar('forum_id'); -$forum_handler =& xoops_getmodulehandler('forum', 'newbb'); -$forum_obj =& $forum_handler->get($forum); -if (!$forum_handler->getPermission($forum_obj)) { - redirect_header("index.php", 2, _MD_NORIGHTTOACCESS); - exit(); -} -if (!$topic_handler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), "view")) { - redirect_header("viewforum.php?forum=" . $forum_obj->getVar('forum_id'), 2, _MD_NORIGHTTOVIEW); - exit(); -} - -$isadmin = newbb_isAdmin($forum_obj); -$perm = false; -if ($isadmin) { - $perm = true; -} elseif ($topic_handler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), "addpoll") - //&& $forum_obj->getVar('allow_polls') == 1 -) { - if ( ($op=="add" || $op=="save") && !$topic_obj->getVar("topic_haspoll") && is_object($xoopsUser) && $xoopsUser->getVar("uid") == $topic_obj->getVar("topic_poster") ) { - $perm = true; - } elseif (!empty($poll_id)) { - $poll = new XoopsPoll($poll_id); - if (is_object($xoopsUser) && $xoopsUser->getVar("uid") == $poll->getVar("user_id")) { - $perm = true; - } - } -} -if (!$perm) { - redirect_header("viewtopic.php?topic_id=" . $topic_id, 2, _NOPERM); -} - -if ( $op == "add" ) { - $poll_form = new XoopsThemeForm(_MD_POLL_CREATNEWPOLL, "poll_form", "polls.php"); - - $question_text = new XoopsFormText(_MD_POLL_POLLQUESTION, "question", 50, 255); - $poll_form->addElement($question_text, true); - - $desc_tarea = new XoopsFormTextarea(_MD_POLL_POLLDESC, "description"); - $poll_form->addElement($desc_tarea); - - $currenttime = formatTimestamp(time(), "Y-m-d H:i:s"); - $endtime = formatTimestamp(time() + 604800, "Y-m-d H:i:s"); - $expire_text = new XoopsFormText(_MD_POLL_EXPIRATION . "<br /><small>" . _MD_POLL_FORMAT . "<br />" . sprintf(_MD_POLL_CURRENTTIME, $currenttime) . "</small>", "end_time", 30, 19, $endtime); - $poll_form->addElement($expire_text); - - $weight_text = new XoopsFormText(_MD_POLL_DISPLAYORDER, "weight", 6, 5, 0); - $poll_form->addElement($weight_text); - - $multi_yn = new XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, "multiple", 0); - $poll_form->addElement($multi_yn); - - $notify_yn = new XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", 1); - $poll_form->addElement($notify_yn); - - $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); - $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); - for($i = 0; $i < 10; $i++) { - $current_bar = (current($barcolor_array) != "blank.gif") ? current($barcolor_array) : next($barcolor_array); - $option_text = new XoopsFormText("", "option_text[]", 50, 255); - $option_tray->addElement($option_text); - $color_select = new XoopsFormSelect("", "option_color[{$i}]", $current_bar); - $color_select->addOptionArray($barcolor_array); - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/".$pollmodules."/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); - $color_label = new XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/".$pollmodules."/images/colorbars/" . $current_bar . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br />"); - $option_tray->addElement($color_select); - $option_tray->addElement($color_label); - if ( !next($barcolor_array) ) { - reset($barcolor_array); - } - unset($color_select, $color_label); - } - $poll_form->addElement($option_tray); - - $submit_button = new XoopsFormButton("", "poll_submit", _SUBMIT, "submit"); - $poll_form->addElement($submit_button); - $op_hidden = new XoopsFormHidden("op", "save"); - $poll_form->addElement($op_hidden); - $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); - $poll_form->addElement($poll_topic_id_hidden); - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - $poll_form->display(); - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -if ( $op == "save" ) { - /* - * The option check should be done before submitting - */ - $option_empty = true; - if (empty($_POST['option_text'])) { - redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - } - $option_text = $_POST['option_text']; - foreach ( $option_text as $optxt ) { - if ( trim($optxt) != "" ) { - $option_empty = false; - break; - } - } - if ($option_empty) { - redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - } - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll(); - else if ( $pollmodules == 'umfrage') - $poll = new Umfrage(); - else die("POLL-ERROR: polls.php Line 190"); - $poll->setVar("question", @$_POST['question']); - $poll->setVar("description", @$_POST['description']); - if ( !empty($_POST['end_time']) ) { - $timezone = is_object($xoopsUser) ? $xoopsUser->getVar("timezone") : null; - $poll->setVar("end_time", userTimeToServerTime(strtotime($_POST['end_time']), $timezone)); - } else { - // if expiration date is not set, set it to 10 days from now - $poll->setVar("end_time", time() + (86400 * 10)); - } - $poll->setVar("display", 0); - $poll->setVar("weight", intval(@$_POST['weight'])); - $poll->setVar("multiple", intval(@$_POST['multiple'])); - if ( !empty($_POST["notify"]) ) { - // if notify, set mail status to "not mailed" - $poll->setVar("mail_status", POLL_NOTMAILED); - } else { - // if not notify, set mail status to already "mailed" - $poll->setVar("mail_status", POLL_MAILED); - } - $uid = is_object($xoopsUser) ? $xoopsUser->getVar("uid") : 0; - $poll->setVar("user_id", $uid); - $new_poll_id = $poll->store(); - $option_color = empty($_POST['option_color']) ? NULL : $_POST['option_color']; - if ( !empty($new_poll_id) ) { - $i = 0; - foreach ( $option_text as $optxt ) { - $optxt = trim($optxt); - if ( $optxt != "" ) { - if ( $pollmodules == 'xoopspoll') - $option = new XoopsPollOption(); - else if ( $pollmodules == 'umfrage') - $option = new UmfrageOption(); - else die("POLL-ERROR: polls.php Line 223"); - $option->setVar("option_text", $optxt); - $option->setVar("option_color", $option_color[$i]); - $option->setVar("poll_id", $new_poll_id); - $option->store(); - } - $i++; - } - $sql = "UPDATE " . $xoopsDB->prefix("bb_topics") . " SET topic_haspoll = 1, poll_id = {$new_poll_id} WHERE topic_id = {$topic_id}"; - if ( !$result = $xoopsDB->query($sql) ) { - xoops_error($xoopsDB->error()); - } - include_once XOOPS_ROOT_PATH . '/class/template.php'; - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); - } else { - xoops_error($poll->getHtmlErrors()); - exit(); - } - redirect_header("viewtopic.php?topic_id={$topic_id}",1,_MD_POLL_DBUPDATED); - //exit(); -} - -if ( $op == "edit" ) { - $pollid = intval($_GET['poll_id']); - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($pollid); - else if ( $pollmodules == 'umfrage') - $poll = new Umfrage($pollid); - $poll_form = new XoopsThemeForm(_MD_POLL_EDITPOLL, "poll_form", "polls.php"); - $author_label = new XoopsFormLabel(_MD_POLL_AUTHOR, "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poll->getVar("user_id") . "'>" . newbb_getUnameFromId($poll->getVar("user_id"), $xoopsModuleConfig['show_realname']) . "</a>"); - $poll_form->addElement($author_label); - $question_text = new XoopsFormText(_MD_POLL_POLLQUESTION, "question", 50, 255, $poll->getVar("question", "E")); - $poll_form->addElement($question_text); - $desc_tarea = new XoopsFormTextarea(_MD_POLL_POLLDESC, "description", $poll->getVar("description", "E")); - $poll_form->addElement($desc_tarea); - $date = formatTimestamp($poll->getVar("end_time"), "Y-m-d H:i:s"); - if ( !$poll->hasExpired() ) { - $expire_text = new XoopsFormText(_MD_POLL_EXPIRATION . "<br /><small>" . _MD_POLL_FORMAT . "<br />" . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), "Y-m-d H:i:s")) . "</small>", "end_time", 20, 19, $date); - $poll_form->addElement($expire_text); - } else { - $restart_label = new XoopsFormLabel(_MD_POLL_EXPIRATION, sprintf(_MD_POLL_EXPIREDAT, $date) . "<br /><a href='polls.php?op=restart&poll_id=" . $poll->getVar("poll_id") . "'>" . _MD_POLL_RESTART . "</a>"); - $poll_form->addElement($restart_label); - } - $weight_text = new XoopsFormText(_MD_POLL_DISPLAYORDER, "weight", 6, 5, $poll->getVar("weight")); - $poll_form->addElement($weight_text); - $multi_yn = new XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, "multiple", $poll->getVar("multiple")); - $poll_form->addElement($multi_yn); - if ( $pollmodules == 'xoopspoll') - $options_arr = XoopsPollOption::getAllByPollId($poll->getVar("poll_id")); - else - $options_arr =& UmfrageOption::getAllByPollId($poll->getVar("poll_id")); - $notify_value = 1; - if ( $poll->getVar("mail_status") != 0 ) { - $notify_value = 0; - } - $notify_yn = new XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", $notify_value); - $poll_form->addElement($notify_yn); - $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); - $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); - $i = 0; - foreach ($options_arr as $option) { - $option_text = new XoopsFormText("", "option_text[]", 50, 255, $option->getVar("option_text")); - $option_tray->addElement($option_text); - $option_id_hidden = new XoopsFormHidden("option_id[]", $option->getVar("option_id")); - $option_tray->addElement($option_id_hidden); - $color_select = new XoopsFormSelect("", "option_color[{$i}]", $option->getVar("option_color")); - $color_select->addOptionArray($barcolor_array); - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[".$i."]\", \"modules/".$pollmodules."/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); - $color_label = new XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/".$pollmodules."/images/colorbars/" . $option->getVar("option_color", "E") . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br />"); - $option_tray->addElement($color_select); - $option_tray->addElement($color_label); - unset($color_select, $color_label, $option_id_hidden, $option_text); - $i++; - } - $more_label = new XoopsFormLabel("", "<br /><a href='polls.php?op=addmore&poll_id=" . $poll->getVar("poll_id") . "&topic_id=" . $topic_id . "'>" . _MD_POLL_ADDMORE . "</a>"); - $option_tray->addElement($more_label); - $poll_form->addElement($option_tray); - $op_hidden = new XoopsFormHidden("op", "update"); - $poll_form->addElement($op_hidden); - $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); - $poll_form->addElement($poll_topic_id_hidden); - $poll_id_hidden = new XoopsFormHidden("poll_id", $poll->getVar("poll_id")); - $poll_form->addElement($poll_id_hidden); - $submit_button = new XoopsFormButton("", "poll_submit", _SUBMIT, "submit"); - $poll_form->addElement($submit_button); - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - $poll_form->display(); - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -if ( $op == "update" ) { - $option_empty = true; - if (empty($_POST['option_text'])) { - redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - } - $option_text = $_POST['option_text']; - foreach ( $option_text as $optxt ) { - if ( trim($optxt) != "" ) { - $option_empty = false; - break; - } - } - if ($option_empty) redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($poll_id); - else - $poll = new Umfrage($poll_id); - $poll->setVar("question", @$_POST['question']); - $poll->setVar("description", @$_POST['description']); - $end_time = (empty($_POST['end_time'])) ? "" : $_POST['end_time']; - if ( !empty($end_time) ) { - $timezone = is_object($xoopsUser) ? $xoopsUser->getVar("timezone") : null; - $poll->setVar("end_time", userTimeToServerTime(strtotime($end_time), $timezone)); - } - $poll->setVar("display", 0); - $poll->setVar("weight", intval(@$_POST['weight'])); - $poll->setVar("multiple", intval(@$_POST['multiple'])); - if ( !empty($_POST["notify"]) && $end_time > time() ) { - // if notify, set mail status to "not mailed" - $poll->setVar("mail_status", POLL_NOTMAILED); - } else { - // if not notify, set mail status to already "mailed" - $poll->setVar("mail_status", POLL_MAILED); - } - if ( !$poll->store() ) { - exit(); - } - $i = 0; - $option_id = (empty($_POST['option_id'])) ? NULL : $_POST['option_id']; - $option_color = (empty($_POST['option_color'])) ? NULL : $_POST['option_color']; - foreach ( $option_id as $opid ) { - if ( $pollmodules == 'xoopspoll') { - $option = new XoopsPollOption($opid); - $option_text[$i] = trim ($option_text[$i]); - if ( $option_text[$i] != "" ) { - $option->setVar("option_text", $option_text[$i]); - $option->setVar("option_color", $option_color[$i]); - $option->store(); - } else { - if ( $option->delete() != false ) { - XoopsPollLog::deleteByOptionId($option->getVar("option_id")); - } - } - } else { - $option = new UmfrageOption($opid); - $option_text[$i] = trim ($option_text[$i]); - if ( $option_text[$i] != "" ) { - $option->setVar("option_text", $option_text[$i]); - $option->setVar("option_color", $option_color[$i]); - $option->store(); - } else { - if ( $option->delete() != false ) { - UmfrageLog::deleteByOptionId($option->getVar("option_id")); - } - } - } - $i++; - } - $poll->updateCount(); - include_once XOOPS_ROOT_PATH . '/class/template.php'; - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); - redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED); - //exit(); -} - -if ( $op == "addmore" ) { - $pollid = intval($_GET['poll_id']); - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($pollid); - else if ( $pollmodules == 'umfrage') - $poll = new Umfrage($pollid); - $poll_form = new XoopsThemeForm(_MD_POLL_ADDMORE, "poll_form", "polls.php"); - $question_label = new XoopsFormLabel(_MD_POLL_POLLQUESTION, $poll->getVar("question")); - $poll_form->addElement($question_label); - $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); - $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); - for($i = 0; $i < 10; $i++) { - $current_bar = (current($barcolor_array) != "blank.gif") ? current($barcolor_array) : next($barcolor_array); - $option_text = new XoopsFormText("", "option_text[]", 50, 255); - $option_tray->addElement($option_text); - $color_select = new XoopsFormSelect("", "option_color[{$i}]", $current_bar); - $color_select->addOptionArray($barcolor_array); - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/".$pollmodules."/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); - $color_label = new XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/".$pollmodules."/images/colorbars/{$current_bar}' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br />"); - $option_tray->addElement($color_select); - $option_tray->addElement($color_label); - unset($color_select, $color_label, $option_text); - if ( !next($barcolor_array) ) { - reset($barcolor_array); - } - } - $poll_form->addElement($option_tray); - $submit_button = new XoopsFormButton("", "poll_submit", _SUBMIT, "submit"); - $poll_form->addElement($submit_button); - $op_hidden = new XoopsFormHidden("op", "savemore"); - $poll_form->addElement($op_hidden); - $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); - $poll_form->addElement($poll_topic_id_hidden); - $poll_id_hidden = new XoopsFormHidden("poll_id", $poll->getVar("poll_id")); - $poll_form->addElement($poll_id_hidden); - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - $poll_form->display(); - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -if ( $op == "savemore" ) { - $option_empty = true; - if (empty($_POST['option_text'])) { - redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - } - $option_text = $_POST['option_text']; - foreach ( $option_text as $optxt ) { - if ( trim($optxt) != "" ) { - $option_empty = false; - break; - } - } - if ($option_empty) redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); - - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($poll_id); - else - $poll = new Umfrage($poll_id); - $i = 0; - $option_color = (empty($_POST['option_color'])) ? NULL : $_POST['option_color']; - foreach ( $option_text as $optxt ) { - $optxt = trim($optxt); - if ( $optxt != "" ) { - if ( $pollmodules == 'xoopspoll') $option = new XoopsPollOption(); - else $option = new UmfrageOption(); - $option->setVar("option_text", $optxt); - $option->setVar("poll_id", $poll->getVar("poll_id")); - $option->setVar("option_color", $option_color[$i]); - $option->store(); - } - $i++; - } - include_once XOOPS_ROOT_PATH . '/class/template.php'; - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); - redirect_header("polls.php?op=edit&poll_id=" . $poll->getVar("poll_id") . "&topic_id=" . $topic_id, 1, _MD_POLL_DBUPDATED); - //exit(); -} - -if ( $op == "delete" ) { - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - $poll = new XoopsPoll($_GET['poll_id']); - xoops_confirm(array('op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll->getVar('poll_id')), 'polls.php', sprintf(_MD_POLL_RUSUREDEL, $poll->getVar("question"))); - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -if ( $op == "delete_ok" ) { - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($poll_id); - else - $poll = new Umfrage($poll_id); - if ( $poll->delete() != false ) { - if ( $pollmodules == 'xoopspoll') { - XoopsPollOption::deleteByPollId($poll->getVar("poll_id")); - XoopsPollLog::deleteByPollId($poll->getVar("poll_id")); - } else { - UmfrageOption::deleteByPollId($poll->getVar("poll_id")); - UmfrageLog::deleteByPollId($poll->getVar("poll_id")); - } - include_once XOOPS_ROOT_PATH . '/class/template.php'; - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); - // delete comments for this poll - xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id')); - $sql = "UPDATE " . $xoopsDB->prefix("bb_topics") . " SET votes = 0, topic_haspoll = 0, poll_id = 0 WHERE topic_id = {$topic_id}"; - if ( !$result = $xoopsDB->query($sql) ) { - //xoops_error($xoopsDB->error()); - } - } - redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED); - //exit(); -} - -if ( $op == "restart" ) { - $pollid = intval($_GET['poll_id']); - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($pollid); - else if ( $pollmodules == 'umfrage') - $poll = new Umfrage($pollid); - $poll_form = new XoopsThemeForm(_MD_POLL_RESTARTPOLL, "poll_form", "polls.php"); - $expire_text = new XoopsFormText(_MD_POLL_EXPIRATION . "<br /><small>" . _MD_POLL_FORMAT . "<br />" . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), "Y-m-d H:i:s")) . "</small>", "end_time", 20, 19, formatTimestamp(time() + 604800, "Y-m-d H:i:s")); - $poll_form->addElement($expire_text); - $notify_yn = new XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", 1); - $poll_form->addElement($notify_yn); - $reset_yn = new XoopsFormRadioYN(_MD_POLL_RESET, "reset", 0); - $poll_form->addElement($reset_yn); - $op_hidden = new XoopsFormHidden("op", "restart_ok"); - $poll_form->addElement($op_hidden); - $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); - $poll_form->addElement($poll_topic_id_hidden); - $poll_id_hidden = new XoopsFormHidden("poll_id", $poll->getVar("poll_id")); - $poll_form->addElement($poll_id_hidden); - $submit_button = new XoopsFormButton("", "poll_submit", _MD_POLL_RESTART, "submit"); - $poll_form->addElement($submit_button); - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - $poll_form->display(); - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -if ( $op == "restart_ok" ) { - if ( $pollmodules == 'xoopspoll') - $poll = new XoopsPoll($poll_id); - else - $poll = new Umfrage($poll_id); - $end_time = (empty($_POST['end_time'])) ? "" : $_POST['end_time']; - if ( !empty($end_time) ) { - $timezone = is_object($xoopsUser) ? $xoopsUser->getVar("timezone") : null; - $poll->setVar("end_time", userTimeToServerTime(strtotime($end_time), $timezone)); - } else { - $poll->setVar("end_time", time() + (86400 * 10)); - } - if ( !empty($_POST["notify"]) && $end_time > time() ) { - // if notify, set mail status to "not mailed" - $poll->setVar("mail_status", POLL_NOTMAILED); - } else { - // if not notify, set mail status to already "mailed" - $poll->setVar("mail_status", POLL_MAILED); - } - if ( !empty($_POST["reset"]) ) { - // reset all logs - if ( $pollmodules == 'xoopspoll') { - XoopsPollLog::deleteByPollId($poll->getVar("poll_id")); - XoopsPollOption::resetCountByPollId($poll->getVar("poll_id")); - } else { - UmfrageLog::deleteByPollId($poll->getVar("poll_id")); - UmfrageOption::resetCountByPollId($poll->getVar("poll_id")); - } - } - if (!$poll->store()) { - //xoops_error($poll->getHtmlErrors()); - exit(); - } - $poll->updateCount(); - include_once XOOPS_ROOT_PATH . '/class/template.php'; - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); - redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED); - //exit(); -} - -if ( $op == "log" ) { - //include XOOPS_ROOT_PATH . "/header.php"; - echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; - echo "<br />View Log<br /> Sorry, not yet. ;-)"; - //include XOOPS_ROOT_PATH . "/footer.php"; - //exit(); -} - -include XOOPS_ROOT_PATH . "/footer.php"; +<?php +/** + * Newbb module + * + * 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. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package newbb + * @since 4.0 + * @author Taiwen Jiang <ph...@us...> + * @version $Id: polls.php 2175 2008-09-23 14:07:03Z phppp $ + */ + + +include_once dirname(__FILE__) . "/header.php"; + +include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; +include_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; +include_once XOOPS_ROOT_PATH . "/class/xoopsblock.php"; + +if ( $pollmodules == 'xoopspoll') +{ + include XOOPS_ROOT_PATH . "/modules/xoopspoll/include/constants.php"; + include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspoll.php"; + include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspolloption.php"; + include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspolllog.php"; + include_once XOOPS_ROOT_PATH . "/modules/xoopspoll/class/xoopspollrenderer.php"; +} +elseif ($pollmodules == 'umfrage') +{ + include XOOPS_ROOT_PATH."/modules/umfrage/include/constants.php"; + include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfrage.php"; + include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfrageoption.php"; + include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfragelog.php"; + include_once XOOPS_ROOT_PATH."/modules/umfrage/class/umfragerenderer.php"; +} +else +{ + redirect_header("javascript:history.go(-1);", 2, _MD_POLLMODULE_ERROR); + exit(); +} + +$op = "add"; +if (isset($_GET['op'])) $op = $_GET['op']; +if (isset($_POST['op'])) $op = $_POST['op']; +if (isset($_GET['poll_id'])) $poll_id = intval($_GET['poll_id']); +if (isset($_POST['poll_id'])) $poll_id = intval($_POST['poll_id']); +if (isset($_GET['topic_id'])) $topic_id = intval($_GET['topic_id']); +if (isset($_POST['topic_id'])) $topic_id = intval($_POST['topic_id']); + +if (!isset($module_handler)) $module_handler =& xoops_gethandler('module'); +$xoopspoll =& $module_handler->getByDirname($pollmodules); +if (!is_object($xoopspoll) || !$xoopspoll->getVar('isactive')) { + redirect_header("javascript:history.go(-1);", 2, _MD_POLLMODULE_ERROR); + exit(); +} + +include XOOPS_ROOT_PATH . "/header.php"; + +$topic_handler =& xoops_getmodulehandler('topic', 'newbb'); +$topic_obj =& $topic_handler->get($topic_id); +$forum = $topic_obj->getVar('forum_id'); +$forum_handler =& xoops_getmodulehandler('forum', 'newbb'); +$forum_obj =& $forum_handler->get($forum); +if (!$forum_handler->getPermission($forum_obj)) { + redirect_header("index.php", 2, _MD_NORIGHTTOACCESS); + exit(); +} +if (!$topic_handler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), "view")) { + redirect_header("viewforum.php?forum=" . $forum_obj->getVar('forum_id'), 2, _MD_NORIGHTTOVIEW); + exit(); +} + +$isadmin = newbb_isAdmin($forum_obj); +$perm = false; +if ($isadmin) { + $perm = true; +} elseif ($topic_handler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), "addpoll") + //&& $forum_obj->getVar('allow_polls') == 1 +) { + if ( ($op=="add" || $op=="save") && !$topic_obj->getVar("topic_haspoll") && is_object($xoopsUser) && $xoopsUser->getVar("uid") == $topic_obj->getVar("topic_poster") ) { + $perm = true; + } elseif (!empty($poll_id)) { + $poll = new XoopsPoll($poll_id); + if (is_object($xoopsUser) && $xoopsUser->getVar("uid") == $poll->getVar("user_id")) { + $perm = true; + } + } +} +if (!$perm) { + redirect_header("viewtopic.php?topic_id=" . $topic_id, 2, _NOPERM); +} + +if ( $op == "add" ) { + $poll_form = new XoopsThemeForm(_MD_POLL_CREATNEWPOLL, "poll_form", "polls.php"); + + $question_text = new XoopsFormText(_MD_POLL_POLLQUESTION, "question", 50, 255); + $poll_form->addElement($question_text, true); + + $desc_tarea = new XoopsFormTextarea(_MD_POLL_POLLDESC, "description"); + $poll_form->addElement($desc_tarea); + + $currenttime = formatTimestamp(time(), "Y-m-d H:i:s"); + $endtime = formatTimestamp(time() + 604800, "Y-m-d H:i:s"); + $expire_text = new XoopsFormText(_MD_POLL_EXPIRATION . "<br /><small>" . _MD_POLL_FORMAT . "<br />" . sprintf(_MD_POLL_CURRENTTIME, $currenttime) . "</small>", "end_time", 30, 19, $endtime); + $poll_form->addElement($expire_text); + + $weight_text = new XoopsFormText(_MD_POLL_DISPLAYORDER, "weight", 6, 5, 0); + $poll_form->addElement($weight_text); + + $multi_yn = new XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, "multiple", 0); + $poll_form->addElement($multi_yn); + + $notify_yn = new XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", 1); + $poll_form->addElement($notify_yn); + + $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); + $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); + for($i = 0; $i < 10; $i++) { + $current_bar = (current($barcolor_array) != "blank.gif") ? current($barcolor_array) : next($barcolor_array); + $option_text = new XoopsFormText("", "option_text[]", 50, 255); + $option_tray->addElement($option_text); + $color_select = new XoopsFormSelect("", "option_color[{$i}]", $current_bar); + $color_select->addOptionArray($barcolor_array); + $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/".$pollmodules."/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); + $color_label = new XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/".$pollmodules."/images/colorbars/" . $current_bar . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br />"); + $option_tray->addElement($color_select); + $option_tray->addElement($color_label); + if ( !next($barcolor_array) ) { + reset($barcolor_array); + } + unset($color_select, $color_label); + } + $poll_form->addElement($option_tray); + + $submit_button = new XoopsFormButton("", "poll_submit", _SUBMIT, "submit"); + $poll_form->addElement($submit_button); + $op_hidden = new XoopsFormHidden("op", "save"); + $poll_form->addElement($op_hidden); + $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); + $poll_form->addElement($poll_topic_id_hidden); + //include XOOPS_ROOT_PATH . "/header.php"; + echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; + $poll_form->display(); + //include XOOPS_ROOT_PATH . "/footer.php"; + //exit(); +} + +if ( $op == "save" ) { + /* + * The option check should be done before submitting + */ + $option_empty = true; + if (empty($_POST['option_text'])) { + redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); + } + $option_text = $_POST['option_text']; + foreach ( $option_text as $optxt ) { + if ( trim($optxt) != "" ) { + $option_empty = false; + break; + } + } + if ($option_empty) { + redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); + } + if ( $pollmodules == 'xoopspoll') + $poll = new XoopsPoll(); + else if ( $pollmodules == 'umfrage') + $poll = new Umfrage(); + else die("POLL-ERROR: polls.php Line 190"); + $poll->setVar("question", @$_POST['question']); + $poll->setVar("description", @$_POST['description']); + if ( !empty($_POST['end_time']) ) { + $timezone = is_object($xoopsUser) ? $xoopsUser->getVar("timezone") : null; +// Start user input time in hegira date - hacked by irmtfan (www.jadoogaran.org) +// $_POST['end_time']=inputTimeToGregorian($_POST['end_time']); + $poll->setVar("end_time", userTimeToServerTime(XoopsLocal::strtotime($_POST['end_time']), $timezone)); +// End user input time in hegira date - hacked by irmtfan (www.jadoogaran.org) + } else { + // if expiration date is not set, set it to 10 days from now + $poll->setVar("end_time", time() + (86400 * 10)); + } + $poll->setVar("display", 0); + $poll->setVar("weight", intval(@$_POST['weight'])); + $poll->setVar("multiple", intval(@$_POST['multiple'])); + if ( !empty($_POST["notify"]) ) { + // if notify, set mail status to "not mailed" + $poll->setVar("mail_status", POLL_NOTMAILED); + } else { + // if not notify, set mail status to already "mailed" + $poll->setVar("mail_status", POLL_MAILED); + } + $uid = is_object($xoopsUser) ? $xoopsUser->getVar("uid") : 0; + $poll->setVar("user_id", $uid); + $new_poll_id = $poll->store(); + $option_color = empty($_POST['option_color']) ? NULL : $_POST['option_color']; + if ( !empty($new_poll_id) ) { + $i = 0; + foreach ( $option_text as $optxt ) { + $optxt = trim($optxt); + if ( $optxt != "" ) { + if ( $pollmodules == 'xoopspoll') + $option = new XoopsPollOption(); + else if ( $pollmodules == 'umfrage') + $option = new UmfrageOption(); + else die("POLL-ERROR: polls.php Line 223"); + $option->setVar("option_text", $optxt); + $option->setVar("option_color", $option_color[$i]); + $option->setVar("poll_id", $new_poll_id); + $option->store(); + } + $i++; + } + $sql = "UPDATE " . $xoopsDB->prefix("bb_topics") . " SET topic_haspoll = 1, poll_id = {$new_poll_id} WHERE topic_id = {$topic_id}"; + if ( !$result = $xoopsDB->query($sql) ) { + xoops_error($xoopsDB->error()); + } + include_once XOOPS_ROOT_PATH . '/class/template.php'; + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); + } else { + xoops_error($poll->getHtmlErrors()); + exit(); + } + redirect_header("viewtopic.php?topic_id={$topic_id}",1,_MD_POLL_DBUPDATED); + //exit(); +} + +if ( $op == "edit" ) { + $pollid = intval($_GET['poll_id']); + if ( $pollmodules == 'xoopspoll') + $poll = new XoopsPoll($pollid); + else if ( $pollmodules == 'umfrage') + $poll = new Umfrage($pollid); + $poll_form = new XoopsThemeForm(_MD_POLL_EDITPOLL, "poll_form", "polls.php"); + $author_label = new XoopsFormLabel(_MD_POLL_AUTHOR, "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poll->getVar("user_id") . "'>" . newbb_getUnameFromId($poll->getVar("user_id"), $xoopsModuleConfig['show_realname']) . "</a>"); + $poll_form->addElement($author_label); + $question_text = new XoopsFormText(_MD_POLL_POLLQUESTION, "question", 50, 255, $poll->getVar("question", "E")); + $poll_form->addElement($question_text); + $desc_tarea = new XoopsFormTextarea(_MD_POLL_POLLDESC, "description", $poll->getVar("description", "E")); + $poll_form->addElement($desc_tarea); + $date = formatTimestamp($poll->getVar("end_time"), "Y-m-d H:i:s"); + if ( !$poll->hasExpired() ) { + $expire_text = new XoopsFormText(_MD_POLL_EXPIRATION . "<br /><small>" . _MD_POLL_FORMAT . "<br />" . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), "Y-m-d H:i:s")) . "</small>", "end_time", 20, 19, $date); + $poll_form->addElement($expire_text); + } else { + $restart_label = new XoopsFormLabel(_MD_POLL_EXPIRATION, sprintf(_MD_POLL_EXPIREDAT, $date) . "<br /><a href='polls.php?op=restart&poll_id=" . $poll->getVar("poll_id") . "'>" . _MD_POLL_RESTART . "</a>"); + $poll_form->addElement($restart_label); + } + $weight_text = new XoopsFormText(_MD_POLL_DISPLAYORDER, "weight", 6, 5, $poll->getVar("weight")); + $poll_form->addElement($weight_text); + $multi_yn = new XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, "multiple", $poll->getVar("multiple")); + $poll_form->addElement($multi_yn); + if ( $pollmodules == 'xoopspoll') + $options_arr = XoopsPollOption::getAllByPollId($poll->getVar("poll_id")); + else + $options_arr =& UmfrageOption::getAllByPollId($poll->getVar("poll_id")); + $notify_value = 1; + if ( $poll->getVar("mail_status") != 0 ) { + $notify_value = 0; + } + $notify_yn = new XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", $notify_value); + $poll_form->addElement($notify_yn); + $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); + $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); + $i = 0; + foreach ($options_arr as $option) { + $option_text = new XoopsFormText("", "option_text[]", 50, 255, $option->getVar("option_text")); + $option_tray->addElement($option_text); + $option_id_hidden = new XoopsFormHidden("option_id[]", $option->getVar("option_id")); + $option_tray->addElement($option_id_hidden); + $color_select = new XoopsFormSelect("", "option_color[{$i}]", $option->getVar("option_color")); + $color_select->addOptionArray($barcolor_array); + $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[".$i."]\", \"modules/".$pollmodules."/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); + $color_label = new XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/".$pollmodules."/images/colorbars/" . $option->getVar("option_color", "E") . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br />"); + $option_tray->addElement($color_select); + $option_tray->addElement($color_label); + unset($color_select, $color_label, $option_id_hidden, $option_text); + $i++; + } + $more_label = new XoopsFormLabel("", "<br /><a href='polls.php?op=addmore&poll_id=" . $poll->getVar("poll_id") . "&topic_id=" . $topic_id . "'>" . _MD_POLL_ADDMORE . "</a>"); + $option_tray->addElement($more_label); + $poll_form->addElement($option_tray); + $op_hidden = new XoopsFormHidden("op", "update"); + $poll_form->addElement($op_hidden); + $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id); + $poll_form->addElement($poll_topic_id_hidden); + $poll_id_hidden = new XoopsFormHidden("poll_id", $poll->getVar("poll_id")); + $poll_form->addElement($poll_id_hidden); + $submit_button = new XoopsFormButton("", "poll_submit", _SUBMIT, "submit"); + $poll_form->addElement($submit_button); + //include XOOPS_ROOT_PATH . "/header.php"; + echo "<h4>" . _MD_POLL_POLLCONF . "</h4>"; + $poll_form->display(); + //include XOOPS_ROOT_PATH . "/footer.php"; + //exit(); +} + +if ( $op == "update" ) { + $option_empty = true; + if (empty($_POST['option_text'])) { + redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); + } + $option_text = $_POST['option_text']; + foreach ( $option_text as $optxt ) { + if ( trim($optxt) != "" ) { + $option_empty = false; + break; + } + } + if ($option_empty) redirect_header("javascript:history.go(-1);", 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !'); + + if ( $pollmodules == 'xoopspoll') + $poll = new XoopsPoll($poll_id); + else + $poll = new Umfrage($poll_id); + $poll->setVar("question", @$_POST['question']); + $poll->setVar("description", @$_POST['description']); + $end_time = (empty($_POST['end_time'])) ? "" : $_POST['end_time']; + if ( !empty($end_time) ) { + $timezone = is_object($xoopsUser) ? $xoopsUser->getVar("timezone") : null; +// Start user input time in hegira date - hacked by irmtfan (www.jadoogaran.org) +// $end_time=inputTimeToGregorian($end_time); + $poll->setVar("end_time", userTimeToServerTime(XoopsLocal::strtotime($end_time), $timezone)); +// End user input time in hegira date - hacked by irmtfan (www.jadoogaran.org) + + } + $poll->setVar("display", 0); + $poll->setVar("weight", intval(@$_POST['weight'])); + $poll->setVar("multiple", intval(@$_POST['multiple'])); + if ( !empty($_POST["notify"]) && $end_time > time() ) { + // if notify, set mail status to "not mailed" + $poll->setVar("mail_status", POLL_NOTMAILED); + } else { + // if not notify, set mail status to already "mailed" + $poll->setVar("mail_status", POLL_MAILED); + } + if ( !$poll->store() ) { + exit(); + } + $i = 0; + $option_id = (empty($_POST['option_id'])) ? NULL : $_POST['option_id']; + $option_color = (empty($_POST['option_color'])) ? NULL : $_POST['option_color']; + foreach ( $option_id as $opid ) { + if ( $pollmodules == 'xoopspoll') { + $option = new XoopsPollOption($opid); + $option_text[$i] = trim ($option_text[$i]); + if ( $option_text[$i] != "" ) { + $option->setVar("option_text", $option_text[$i]); + $option->setVar("option_color", $option_color[$i]); + $option->store(); + } else { + if ( $option->delete() != false ) { + XoopsPollLog::deleteByOptionId($option->getVar("option_id")); + } + } + } else { + $option = new UmfrageOption($opid); + $option_text[$i] = trim ($option_text[$i]); + if ( $option_text[$i] != "" ) { + $option->setVar("option_text", $option_text[$i]); + $option->setVar("option_color", $option_color[$i]); + $option->store(); + } else { + if ( $option->delete() != false ) { + UmfrageLog::deleteByOptionId($option->getVar("option_id")); + } + } + } + $i++; + } + $poll->updateCount(); + include_once XOOPS_ROOT_PATH . '/class/template.php'; + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); + redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED); + //exit(); +} + +if ( $op == "addmore" ) { + $pollid = intval($_GET['poll_id']); + if ( $pollmodules == 'xoopspoll') + $poll = new XoopsPoll($pollid); + else if ( $pollmodules == 'umfrage') + $poll = new Umfrage($pollid); + $poll_form = new XoopsThemeForm(_MD_POLL_ADDMORE, "poll_form", "polls.php"); + $question_label = new XoopsFormLabel(_MD_POLL_POLLQUESTION, $poll->getVar("question")); + $poll_form->addElement($question_label); + $option_tray = new XoopsFormElementTray(_MD_POLL_POLLOPTIONS, ""); + $barcolor_array = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/".$pollmodules."/images/colorbars/"); + for($i = 0; $i < 10; $i++) { + $current_bar = (current($barcol... [truncated message content] |