source: temp/test-xoops.ec-cube.net/html/modules/mylinks/submit.php @ 567

Revision 567, 7.1 KB checked in by uehara, 20 years ago (diff)
Line 
1<?php
2// $Id: submit.php,v 1.4 2005/09/04 20:46:10 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7// ------------------------------------------------------------------------- //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27include "header.php";
28$myts =& MyTextSanitizer::getInstance();// MyTextSanitizer object
29include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
30include_once XOOPS_ROOT_PATH."/class/module.errorhandler.php";
31include_once XOOPS_ROOT_PATH."/include/xoopscodes.php";
32
33$eh = new ErrorHandler; //ErrorHandler object
34$mytree = new XoopsTree($xoopsDB->prefix("mylinks_cat"),"cid","pid");
35
36if (empty($xoopsUser) and !$xoopsModuleConfig['anonpost']) {
37    redirect_header(XOOPS_URL."/user.php",2,_MD_MUSTREGFIRST);
38    exit();
39}
40
41if (!empty($_POST['submit'])) {
42
43    $submitter = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
44
45    // RMV - why store submitter on form??
46    //if (!$_POST['submitter'] and $xoopsUser) {
47    //   $submitter = $xoopsUser->uid();
48    //}elseif(!$_POST['submitter'] and !$xoopsUser) {
49    //  $submitter = 0;
50    //}else{
51    //  $submitter = intval($_POST['submitter']);
52    //}
53
54    // Check if Title exist
55    if ($_POST["title"]=="") {
56        $eh->show("1001");
57    }
58
59    // Check if URL exist
60    $url = $_POST["url"];
61    if ($url=="" || !isset($url)) {
62        $eh->show("1016");
63    }
64
65    // Check if Description exist
66    if ($_POST['message']=="") {
67        $eh->show("1008");
68    }
69
70    $notify = !empty($_POST['notify']) ? 1 : 0;
71
72    if ( !empty($_POST['cid']) ) {
73        $cid = intval($_POST['cid']);
74    } else {
75        $cid = 0;
76    }
77
78    //  $url = urlencode($url);
79    $url = $myts->makeTboxData4Save($url);
80
81    $title = $myts->makeTboxData4Save($_POST["title"]);
82    $description = $myts->makeTareaData4Save($_POST["message"]);
83    $date = time();
84    $newid = $xoopsDB->genId($xoopsDB->prefix("mylinks_links")."_lid_seq");
85    if ( $xoopsModuleConfig['autoapprove'] == 1 ) {
86        // RMV-FIXME: shouldn't this be 'APPROVE' or something (also in mydl)?
87        $status = $xoopsModuleConfig['autoapprove'];
88    } else {
89        $status = 0;
90    }
91    $sql = sprintf("INSERT INTO %s (lid, cid, title, url, logourl, submitter, status, date, hits, rating, votes, comments) VALUES (%u, %u, '%s', '%s', '%s', %u, %u, %u, %u, %u, %u, %u)", $xoopsDB->prefix("mylinks_links"), $newid, $cid, $title, $url, ' ', $submitter, $status, $date, 0, 0, 0, 0);
92    $xoopsDB->query($sql) or $eh->show("0013");
93    if ($newid == 0) {
94        $newid = $xoopsDB->getInsertId();
95    }
96    $sql = sprintf("INSERT INTO %s (lid, description) VALUES (%u, '%s')", $xoopsDB->prefix("mylinks_text"), $newid, $description);
97    $xoopsDB->query($sql) or $eh->show("0013");
98    // RMV-NEW
99    // Notify of new link (anywhere) and new link in category.
100    $notification_handler =& xoops_gethandler('notification');
101    $tags = array();
102    $tags['LINK_NAME'] = $title;
103    $tags['LINK_URL'] = XOOPS_URL . '/modules/'. $xoopsModule->getVar('dirname') . '/singlelink.php?cid=' . $cid . '&amp;lid=' . $newid;
104    $sql = "SELECT title FROM " . $xoopsDB->prefix("mylinks_cat") . " WHERE cid=" . $cid;
105    $result = $xoopsDB->query($sql);
106    $row = $xoopsDB->fetchArray($result);
107    $tags['CATEGORY_NAME'] = $row['title'];
108    $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $cid;
109    if ( $xoopsModuleConfig['autoapprove'] == 1 ) {
110        $notification_handler->triggerEvent('global', 0, 'new_link', $tags);
111        $notification_handler->triggerEvent('category', $cid, 'new_link', $tags);
112        redirect_header("index.php",2,_MD_RECEIVED."<br />"._MD_ISAPPROVED."");
113    }else{
114        $tags['WAITINGLINKS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listNewLinks';
115        $notification_handler->triggerEvent('global', 0, 'link_submit', $tags);
116        $notification_handler->triggerEvent('category', $cid, 'link_submit', $tags);
117        if ($notify) {
118            include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
119            $notification_handler->subscribe('link', $newid, 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
120        }
121        redirect_header("index.php",2,_MD_RECEIVED);
122    }
123    exit();
124
125} else {
126
127    $xoopsOption['template_main'] = 'mylinks_submit.html';
128    include XOOPS_ROOT_PATH."/header.php";
129    ob_start();
130    xoopsCodeTarea("message",37,8);
131    $xoopsTpl->assign('xoops_codes', ob_get_contents());
132    ob_end_clean();
133    ob_start();
134    xoopsSmilies("message");
135    $xoopsTpl->assign('xoops_smilies', ob_get_contents());
136    ob_end_clean();
137    $xoopsTpl->assign('notify_show', !empty($xoopsUser) && !$xoopsModuleConfig['autoapprove'] ? 1 : 0);
138    $xoopsTpl->assign('lang_submitonce', _MD_SUBMITONCE);
139    $xoopsTpl->assign('lang_submitlinkh', _MD_SUBMITLINKHEAD);
140    $xoopsTpl->assign('lang_allpending', _MD_ALLPENDING);
141    $xoopsTpl->assign('lang_dontabuse', _MD_DONTABUSE);
142    $xoopsTpl->assign('lang_wetakeshot', _MD_TAKESHOT);
143    $xoopsTpl->assign('lang_sitetitle', _MD_SITETITLE);
144    $xoopsTpl->assign('lang_siteurl', _MD_SITEURL);
145    $xoopsTpl->assign('lang_category', _MD_CATEGORYC);
146    $xoopsTpl->assign('lang_options', _MD_OPTIONS);
147    $xoopsTpl->assign('lang_notify', _MD_NOTIFYAPPROVE);
148    $xoopsTpl->assign('lang_description', _MD_DESCRIPTIONC);
149    $xoopsTpl->assign('lang_submit', _SUBMIT);
150    $xoopsTpl->assign('lang_cancel', _CANCEL);
151
152    $xoopsTpl->assign('lang_caution_title', _POST_CAUTION_TITLE);
153    $xoopsTpl->assign('lang_caution_body', _POST_CAUTION_BODY);
154    ob_start();
155    $mytree->makeMySelBox("title", "title",0,1);
156    $selbox = ob_get_contents();
157    ob_end_clean();
158    $xoopsTpl->assign('category_selbox', $selbox);
159    include XOOPS_ROOT_PATH.'/footer.php';
160}
161?>
Note: See TracBrowser for help on using the repository browser.