XoopsModules25x /
lexikon
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * $Id: submit.php v 1.0 8 May 2004 hsalazar Exp $ |
||
| 4 | * Module: Lexikon - glossary module |
||
| 5 | * Version: v 1.00 |
||
| 6 | * Release Date: 8 May 2004 |
||
| 7 | * Author: hsalazar |
||
| 8 | * Licence: GNU |
||
| 9 | */ |
||
| 10 | |||
| 11 | include( "header.php" ); |
||
| 12 | $xoopsOption['template_main'] = 'lx_submit.html'; |
||
| 13 | include( XOOPS_ROOT_PATH . "/header.php" ); |
||
| 14 | |||
| 15 | include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; |
||
| 16 | |||
| 17 | Global $xoTheme, $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; |
||
| 18 | |||
| 19 | $result = $xoopsDB -> query( "SELECT * FROM " . $xoopsDB -> prefix( "lxcategories" ) . "" ); |
||
| 20 | View Code Duplication | if ( $xoopsDB -> getRowsNum( $result ) == '0' && $xoopsModuleConfig['multicats'] == '1') { |
|
|
0 ignored issues
–
show
|
|||
| 21 | redirect_header( "index.php", 1, _AM_LEXIKON_NOCOLEXISTS ); |
||
| 22 | exit(); |
||
| 23 | } |
||
| 24 | |||
| 25 | /*if ( !is_object( $xoopsUser ) && $xoopsModuleConfig['anonpost'] == 0 ) { |
||
| 26 | redirect_header( "index.php", 1, _NOPERM ); |
||
| 27 | exit(); |
||
| 28 | } |
||
| 29 | if ( is_object( $xoopsUser ) && $xoopsModuleConfig['allowsubmit'] == 0 ) { |
||
| 30 | redirect_header( "index.php", 1, _NOPERM ); |
||
| 31 | exit(); |
||
| 32 | }*/ |
||
| 33 | |||
| 34 | $op = 'form'; |
||
| 35 | |||
| 36 | if ( isset( $_POST['post'] ) ) { |
||
| 37 | $op = trim( 'post' ); |
||
| 38 | } |
||
| 39 | elseif ( isset( $_POST['edit'] ) ) { |
||
| 40 | $op = trim( 'edit' ); |
||
| 41 | } |
||
| 42 | |||
| 43 | //$suggest = isset($_GET['suggest']) ? $_GET['suggest'] : (isset($_POST['suggest']) ? $_POST['suggest'] : ''); |
||
| 44 | $suggest = isset($_GET['suggest']) ? intval((int)$_GET['suggest']):0; |
||
| 45 | |||
| 46 | if ($suggest > 0) { |
||
| 47 | $terminosql = $xoopsDB -> query( "SELECT term FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE datesub < ".time()." AND datesub > 0 AND request = '1' AND entryID = '".$suggest."'" ); |
||
| 48 | list($termino) = $xoopsDB->fetchRow($terminosql); |
||
| 49 | } else { |
||
| 50 | $termino = ''; |
||
| 51 | } |
||
| 52 | //--- Permissions --- |
||
| 53 | $gperm_handler = xoops_gethandler('groupperm'); |
||
| 54 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 55 | $module_id = $xoopsModule->getVar('mid'); |
||
| 56 | $perm_itemid = isset($_POST['categoryID']) ? intval($_POST['categoryID']) : 0; |
||
| 57 | if (!$gperm_handler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id)) { |
||
| 58 | redirect_header('javascript:history.go(-1)', 3, _MD_LEXIKON_MUSTREGFIRST); |
||
| 59 | exit(); |
||
| 60 | } |
||
| 61 | $totalcats = $gperm_handler->getItemIds("lexikon_submit", $groups, $module_id); |
||
| 62 | $permitsubmit =count($totalcats); |
||
| 63 | if ( $permitsubmit == 0 && $xoopsModuleConfig['multicats'] == '1') { |
||
| 64 | redirect_header( "index.php", 3, _NOPERM ); |
||
| 65 | exit(); |
||
| 66 | } |
||
| 67 | switch ( $op ) { |
||
| 68 | case 'post': |
||
| 69 | //--- Captcha |
||
| 70 | if ($xoopsModuleConfig['captcha'] != 0) { |
||
| 71 | xoops_load('XoopsCaptcha'); |
||
| 72 | if(@include_once XOOPS_ROOT_PATH."/class/captcha/xoopscaptcha.php") { |
||
| 73 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
| 74 | //if(! $xoopsCaptcha->verify($_POST["skipmember"]) ) { |
||
| 75 | if (!$xoopsCaptcha->verify()) { |
||
| 76 | echo $xoopsCaptcha->getMessage(); |
||
| 77 | redirect_header("javascript:history.go(-1)", 2, _CAPTCHA_INVALID_CODE ); |
||
| 78 | } |
||
| 79 | //} |
||
| 80 | } |
||
| 81 | } |
||
| 82 | //------- |
||
| 83 | |||
| 84 | Global $xoTheme, $xoopsUser,$xoopsModule,$xoopsModuleConfig; |
||
| 85 | include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/include/functions.php"; |
||
| 86 | $myts = MyTextSanitizer :: getInstance(); |
||
| 87 | //permissions |
||
| 88 | $gperm_handler = xoops_gethandler('groupperm'); |
||
| 89 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 90 | $module_id = $xoopsModule->getVar('mid'); |
||
| 91 | $perm_itemid = isset($_POST['categoryID']) ? intval($_POST['categoryID']) : 0; |
||
| 92 | |||
| 93 | $html = 1; |
||
| 94 | if ( $xoopsUser ) { |
||
| 95 | $uid = $xoopsUser -> getVar( 'uid' ); |
||
| 96 | if ( $xoopsUser -> isAdmin( $xoopsModule -> mid() ) ) { |
||
| 97 | $html = empty( $html ) ? 0 : 1; |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | if (!is_object($xoopsUser) && ($gperm_handler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id))) { |
||
| 101 | $uid = 0; |
||
| 102 | } else { |
||
| 103 | redirect_header( "index.php", 3, _NOPERM ); |
||
| 104 | exit(); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $block = isset( $block ) ? intval( $block ) : 1; |
||
| 109 | $smiley = isset( $smiley ) ? intval( $smiley ) : 1; |
||
| 110 | $xcodes = isset( $xcodes ) ? intval( $xcodes ) : 1; |
||
| 111 | $breaks = isset( $breaks ) ? intval( $breaks ) : 1; |
||
| 112 | //$notifypub = isset( $notifypub ) ? intval( $notifypub ) : 0; |
||
| 113 | //$notifypub = (isset($_POST['notifypub'])) ? intval($_POST['notifypub']) : ''; |
||
| 114 | $notifypub = !empty($_POST['notifypub']) ? 1 : 0; |
||
| 115 | |||
| 116 | if ( $xoopsModuleConfig['multicats'] == 1 ) { |
||
| 117 | $categoryID = intval( $_POST['categoryID'] ); |
||
| 118 | } else { |
||
| 119 | $categoryID = 1; |
||
| 120 | } |
||
| 121 | //$term = $myts->htmlspecialchars($_POST['term']); |
||
| 122 | //$init = substr($term, 0, 1); |
||
| 123 | //$definition = $myts -> addSlashes( $_POST['definition'] ); |
||
| 124 | //$ref = $myts -> addSlashes( $_POST['ref'] ); |
||
| 125 | //$term = $myts->htmlSpecialChars($myts->censorString($_POST['term'] )); |
||
| 126 | $term = $myts->addSlashes($myts->censorString($_POST['term'] )); |
||
| 127 | $definition = $myts -> addSlashes($myts->censorString( $_POST['definition'])); |
||
| 128 | $ref = $myts -> addSlashes($myts->censorString($_POST['ref'] )); |
||
| 129 | $url = $myts -> addSlashes( $_POST['url'] ); |
||
| 130 | if (empty($url)) { |
||
| 131 | $url = ""; |
||
| 132 | } |
||
| 133 | // this is for terms with umlaut or accented initials |
||
| 134 | $term4sql = lx_sanitizeFieldName($myts->htmlspecialchars($_POST['term'])); |
||
| 135 | $init = substr($term4sql, 0, 1); |
||
| 136 | $init = preg_match("/[a-zA-Z]/", $init) ? strtoupper($init) : '#'; |
||
| 137 | |||
| 138 | $datesub = time(); |
||
| 139 | |||
| 140 | $submit = 1; |
||
| 141 | $offline = 1; |
||
| 142 | $request = 0; |
||
| 143 | $block = 1; |
||
| 144 | $autoapprove = 0; |
||
| 145 | |||
| 146 | /*if ( $xoopsModuleConfig['autoapprove'] == 1 ) { |
||
| 147 | $submit = 0; |
||
| 148 | $offline = 0; |
||
| 149 | }*/ |
||
| 150 | if (!$gperm_handler->checkRight('lexikon_approve', $perm_itemid, $groups, $module_id)) { |
||
| 151 | $submit = 0; |
||
| 152 | $offline = 0; |
||
| 153 | $autoapprove = 1; |
||
| 154 | } |
||
| 155 | // verify that the term not exists |
||
| 156 | View Code Duplication | if (lx_TermExists($term,$xoopsDB->prefix('lxentries'))) redirect_header("javascript:history.go(-1)", 2, _MD_LEXIKON_ITEMEXISTS . "<br />" . $term ); |
|
| 157 | $result = $xoopsDB -> query( "INSERT INTO " . $xoopsDB -> prefix( "lxentries" ) . " (entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub ) VALUES ('', '$categoryID', '$term', '$init', '$definition', '$ref', '$url', '$uid', '$submit', '$datesub', '$html', '$smiley', '$xcodes', '$breaks','$block', '$offline', '$notifypub')" ); |
||
| 158 | $newid = $xoopsDB -> getInsertId(); |
||
| 159 | // Increment author's posts count |
||
| 160 | //if ( $xoopsModuleConfig['autoapprove'] == 1 ) { |
||
| 161 | //if (is_object($xoopsUser) && empty($entryID)) { |
||
| 162 | View Code Duplication | if (is_object($xoopsUser) && empty($entryID) && $autoapprove) { |
|
| 163 | $member_handler = xoops_gethandler('member'); |
||
| 164 | $submitter = $member_handler -> getUser($uid); |
||
| 165 | if (is_object($submitter) ) { |
||
| 166 | $submitter -> setVar('posts',$submitter -> getVar('posts') + 1); |
||
| 167 | $res=$member_handler -> insertUser($submitter, true); |
||
| 168 | unset($submitter); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | //} |
||
| 172 | // trigger Notification |
||
| 173 | if(!empty($xoopsModuleConfig['notification_enabled']) ){ |
||
| 174 | global $xoopsModule; |
||
| 175 | if ($newid == 0) { |
||
| 176 | $newid = $xoopsDB->getInsertId(); |
||
| 177 | } |
||
| 178 | $notification_handler = xoops_gethandler('notification'); |
||
| 179 | $tags = array(); |
||
| 180 | $shortdefinition = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $definition ),0,45)); |
||
| 181 | $tags['ITEM_NAME'] = $term; |
||
| 182 | $tags['ITEM_BODY'] = $shortdefinition; |
||
| 183 | $tags['DATESUB'] = formatTimestamp( $datesub, 'd M Y' ); |
||
| 184 | $tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/entry.php?op=mod&entryID='. $newid; |
||
| 185 | $sql = "SELECT name FROM " . $xoopsDB->prefix("lxcategories") . " WHERE categoryID=" . $categoryID; |
||
| 186 | $result = $xoopsDB->query($sql); |
||
| 187 | $row = $xoopsDB->fetchArray($result); |
||
| 188 | $tags['CATEGORY_NAME'] = $row['name']; |
||
| 189 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID; |
||
| 190 | if ( $xoopsModuleConfig['autoapprove'] == 1 ) { |
||
| 191 | $notification_handler->triggerEvent('category', $categoryID, 'new_post', $tags); |
||
| 192 | $notification_handler->triggerEvent('global', 0, 'new_post', $tags); |
||
| 193 | //sample: $notification_handler->triggerEvent($category, $item_id, $events, $tags, $user_list=array(), $module_id=null, $omit_user_id=null) |
||
| 194 | } else { |
||
| 195 | $notification_handler->triggerEvent('global', 0, 'term_submit', $tags); |
||
| 196 | $notification_handler->triggerEvent('category', 0, 'term_submit', $tags); |
||
| 197 | if ($notifypub) { |
||
| 198 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
| 199 | $notification_handler->subscribe('term', $newid, 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | } |
||
| 203 | if ( $result ) { |
||
| 204 | if (!is_object($xoopsUser)) { |
||
| 205 | $username = _MD_LEXIKON_GUEST; |
||
| 206 | $usermail = ''; |
||
| 207 | View Code Duplication | } else { |
|
| 208 | $username = $xoopsUser->getVar("uname", "E"); |
||
| 209 | $result = $xoopsDB->query("select email from ".$xoopsDB->prefix("users")." WHERE uname='$username'"); |
||
| 210 | list($usermail) = $xoopsDB->fetchRow($result); |
||
| 211 | } |
||
| 212 | |||
| 213 | if ($xoopsModuleConfig['mailtoadmin'] == 1) { |
||
| 214 | $adminMessage = sprintf( _MD_LEXIKON_WHOSUBMITTED, $username ); |
||
| 215 | $adminMessage .= "<b>".$term."</b>\n"; |
||
| 216 | $adminMessage .= ""._MD_LEXIKON_EMAILLEFT." $usermail\n"; |
||
| 217 | $adminMessage .= "\n"; |
||
| 218 | if ($notifypub == '1') { |
||
| 219 | $adminMessage .= _MD_LEXIKON_NOTIFYONPUB; |
||
| 220 | } |
||
| 221 | $adminMessage .= "\n".$_SERVER['HTTP_USER_AGENT']."\n"; |
||
| 222 | $subject = $xoopsConfig['sitename']." - "._MD_LEXIKON_DEFINITIONSUB; |
||
| 223 | $xoopsMailer = getMailer(); |
||
| 224 | $xoopsMailer->useMail(); |
||
| 225 | $xoopsMailer->multimailer->IsHTML(true); |
||
| 226 | $xoopsMailer->setToEmails($xoopsConfig['adminmail']); |
||
| 227 | $xoopsMailer->setFromEmail($usermail); |
||
| 228 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
| 229 | $xoopsMailer->setSubject($subject); |
||
| 230 | $xoopsMailer->setBody($adminMessage); |
||
| 231 | $xoopsMailer->send(); |
||
| 232 | $messagesent = sprintf(_MD_LEXIKON_MESSAGESENT,$xoopsConfig['sitename'])."<br />"._MD_LEXIKON_THANKS1.""; |
||
| 233 | } |
||
| 234 | |||
| 235 | //if ( $xoopsModuleConfig['autoapprove'] == 1 ) { |
||
| 236 | if ( $autoapprove == 1 ) { |
||
| 237 | redirect_header( "index.php", 2, _MD_LEXIKON_RECEIVEDANDAPPROVED ); |
||
| 238 | View Code Duplication | } else { |
|
| 239 | //send received mail |
||
| 240 | //if (lx_getmoduleoption('mailtosender') && $usermail) { |
||
| 241 | if ( $xoopsModuleConfig['mailtosender'] == 1 && $usermail) { |
||
| 242 | $conf_subject = _MD_LEXIKON_THANKS3; |
||
| 243 | $userMessage = sprintf(_MD_LEXIKON_GOODDAY2, $username); |
||
| 244 | $userMessage .= "\n\n"; |
||
| 245 | $userMessage .= sprintf(_MD_LEXIKON_THANKYOU3,$xoopsConfig['sitename']); |
||
| 246 | $userMessage .= "\n"; |
||
| 247 | $userMessage .= sprintf(_MD_LEXIKON_SUBMISSIONSENT,$xoopsConfig['sitename']); |
||
| 248 | $userMessage .= "\n"; |
||
| 249 | $userMessage .= "--------------\n"; |
||
| 250 | $userMessage .= "".$xoopsConfig['sitename']." "._MD_LEXIKON_WEBMASTER."\n"; |
||
| 251 | $userMessage .= "".$xoopsConfig['adminmail'].""; |
||
| 252 | |||
| 253 | $xoopsMailer = getMailer(); |
||
| 254 | $xoopsMailer->useMail(); |
||
| 255 | $xoopsMailer->multimailer->IsHTML(true); |
||
| 256 | $xoopsMailer->setToEmails($usermail); |
||
| 257 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
| 258 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
| 259 | $xoopsMailer->setSubject($conf_subject); |
||
| 260 | $xoopsMailer->setBody($userMessage); |
||
| 261 | $xoopsMailer->send(); |
||
| 262 | $messagesent = _MD_LEXIKON_RECEIVED."<br />"._MD_LEXIKON_THANKS1.""; |
||
| 263 | $messagesent .= sprintf(_MD_LEXIKON_SENTCONFIRMMAIL,$usermail); |
||
| 264 | } else { |
||
| 265 | $messagesent = sprintf(_MD_LEXIKON_RECEIVED)."<br />"._MD_LEXIKON_THANKS1.""; |
||
| 266 | } |
||
| 267 | redirect_header("index.php", 2, $messagesent ); |
||
| 268 | } |
||
| 269 | } else { |
||
| 270 | redirect_header( "submit.php", 2, _MD_LEXIKON_ERRORSAVINGDB ); |
||
| 271 | } |
||
| 272 | exit(); |
||
| 273 | break; |
||
| 274 | |||
| 275 | case 'form': |
||
| 276 | default: |
||
| 277 | global $xoopsUser, $_SERVER; |
||
| 278 | include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/include/functions.php";// to create pagetitle |
||
| 279 | $myts = MyTextSanitizer :: getInstance(); |
||
| 280 | if (!is_object($xoopsUser)) { |
||
| 281 | $name = _MD_LEXIKON_GUEST; |
||
| 282 | } else { |
||
| 283 | $name = ucfirst($xoopsUser->getVar("uname")); |
||
| 284 | } |
||
| 285 | |||
| 286 | $xoopsTpl -> assign ( 'send_def_to', sprintf(_MD_LEXIKON_SUB_SNEWNAME,ucfirst($xoopsModule->name())) ); |
||
| 287 | $xoopsTpl -> assign ( 'send_def_g', sprintf(_MD_LEXIKON_SUB_SNEWNAME,ucfirst($xoopsModule->name())) ); |
||
| 288 | $xoopsTpl -> assign ( 'lx_user_name', $name ); |
||
| 289 | |||
| 290 | $block = 1; |
||
| 291 | $html = 1; |
||
| 292 | $smiley = 1; |
||
| 293 | $xcodes = 1; |
||
| 294 | $breaks = 1; |
||
| 295 | $categoryID = 0; |
||
| 296 | $notifypub = 1; |
||
| 297 | $term = $termino; |
||
| 298 | $definition = ''; |
||
| 299 | $ref = ''; |
||
| 300 | $url = ''; |
||
| 301 | |||
| 302 | include_once 'include/storyform.inc.php'; |
||
| 303 | |||
| 304 | $xoopsTpl -> assign ( 'modulename', $xoopsModule->dirname()); |
||
| 305 | |||
| 306 | $sform->assign($xoopsTpl); |
||
| 307 | |||
| 308 | $xoopsTpl -> assign ( 'lang_modulename', $xoopsModule->name() ); |
||
| 309 | $xoopsTpl -> assign ( 'lang_moduledirname', $xoopsModule->getVar('dirname') ); |
||
| 310 | $xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()). ' - ' ._MD_LEXIKON_SUBMITART); |
||
| 311 | $xoopsTpl->assign("xoops_module_header", '<link rel="stylesheet" type="text/css" href="style.css" />'); |
||
| 312 | // Meta data |
||
| 313 | $meta_description = _MD_LEXIKON_SUBMITART. ' - ' .$myts->htmlSpecialChars($xoopsModule->name()); |
||
| 314 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 315 | $xoTheme->addMeta( 'meta', 'description', $meta_description); |
||
| 316 | } else { |
||
| 317 | $xoopsTpl->assign('xoops_meta_description', $meta_description); |
||
| 318 | } |
||
| 319 | |||
| 320 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
| 321 | break; |
||
| 322 | } |
||
| 323 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.