"Fossies" - the Fresh Open Source Software Archive

Member "mythreads/lib/lib_addupdate.php3" (23 Jan 2018, 10755 Bytes) of package /linux/privat/mythreads-links_1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "lib_addupdate.php3": 1.2.0_vs_1.2.1.

    1 <?php
    2 #----------------------------------------------------------------->
    3 # $Id: lib_addupdate.php3,v 1.52 2010/05/04 18:29:59 ldrolez Exp $
    4 #
    5 # Website: http://mythreads.sourceforge.net
    6 #
    7 # Desc: lib_addupdate.php3. functions for adding and updating links...
    8 #
    9 # License: This code is released under the terms of the GNU GPL
   10 # version 2 or later. Please refer to www.gnu.org for a copy
   11 # of this license.
   12 #
   13 #----------------------------------------------------------------->
   14 
   15 ###################################################
   16 #
   17 ###################################################
   18 function whatUlink()
   19 {
   20     global $start_script, $tpl;
   21     
   22     $tpl->set_file("geturlinfo", "form_get_url_info.tpl");
   23     $content = $tpl->subst("geturlinfo");
   24 
   25     return $content;
   26 }
   27 
   28 ###################################################
   29 # Form to edit information of an existing link
   30 ###################################################
   31 function viewULink($_unused)
   32 {
   33     global $start_script, $start_script_t, $tpl;
   34     global $config, $custom, $_GET, $mylink;
   35 
   36     # 'link' can be an URL or a number
   37     $n = sqlesc($_GET['link']);
   38     if (preg_match("/^[0-9]+$/", $n, $trash)) {
   39         $result = $mylink->query( "SELECT * FROM ".$config["pre"]."links where idx='$n' and status=0");
   40         $exists = $mylink->query( "SELECT * FROM ".$config["pre"]."links where idx='$n' and status<>0");
   41     } else {
   42         $result = $mylink->query( "SELECT * FROM ".$config["pre"]."links where link='$n' and status=0");
   43         $exists = $mylink->query( "SELECT * FROM ".$config["pre"]."links where link='$n' and status<>0");
   44     }
   45     # one more test should be done: old waiting link
   46     $dothey = mysqli_num_rows($exists);
   47 
   48     if (mysqli_num_rows($result) and ! $dothey)
   49     {
   50     
   51         $info = mysqli_fetch_array($result);
   52         $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category order by pathto");
   53     
   54         $options = "";  
   55         while ($info_c = mysqli_fetch_array($category) )
   56         {
   57         $patharray = explode(":",$info_c["pathto"]);
   58         
   59         if ($info["cat"] == $info_c["cat"])
   60         {
   61         $options .= "<option value=\"$info_c[cat]\" selected>";
   62         }
   63         else
   64         {
   65         $options .= "<option value=\"$info_c[cat]\">";
   66         }
   67         
   68         while (list($key, $val)=each($patharray))
   69         {
   70             if ($val != "") {
   71                 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
   72                 $sub_title_new = mysqli_fetch_array($result_sub);
   73                 $options .= "/$sub_title_new[title]";
   74             }
   75         }
   76         $options .= "</option>\n";
   77         }
   78 
   79         $tpl->set_file("updatelink", "form_update_link.tpl");
   80         $tpl->set_var( array(
   81                  "ACTION" => $start_script_t."mode=update_link",
   82                  "SUBMIT_NAME" => "update_link",
   83                  "IDX"  => "$info[idx]",
   84                  "TITLE"  => "$info[title]",
   85                  "MESSAGE" => "$info[message]",
   86                  "LINK"   => "$info[link]",
   87                  "OPTIONS" => "$options"
   88                  ));
   89         # process custom 
   90         while (list($k,$v) = each($custom)) {
   91         $ku = strtoupper($k);
   92         $dt = $info[$k];
   93         if ($dt != "") {
   94             # set data
   95             $tpl->set_var ($ku, filterOut($v, $dt));
   96             # else {
   97             # delete conditional block
   98             # $tpl->set_block ("updatelink", "IFDEF_".$ku, "deleteme");
   99             # FIXME: does it work if there s more than one condition ?
  100         }
  101         }   
  102         
  103         # security code
  104         if ($config{'security_code'} != "" && getuser() != "admin") {
  105         $secret = ImageGenSecret(8);
  106         $ref = ImageGenSecretRef($secret);
  107         $tpl->set_var ("IMG_SECURITY_LINK", "<img src='".$start_script_t."sec_img=".$ref."'>");
  108         $tpl->set_var ("SECURITY", "$ref");     
  109         } else {
  110         # delete security bloc
  111         $tpl->set_block ("updatelink", "security_row", "deleteme");
  112         }
  113         
  114         $content = $tpl->subst("updatelink");
  115         
  116     } else {
  117         if ($dothey) {
  118             $info = mysqli_fetch_array($exists);
  119             $content = Message ("already_waiting", 
  120                                  array ("LINK" => $info["link"]));
  121         } else {
  122             $content = Message ("no_link_for", 
  123                                  array ("TEXT" => htmlentities($_GET[link])));
  124         }
  125     }
  126     
  127     return $content;
  128 }
  129 
  130 ###################################################
  131 # Add a link in the waiting queue
  132 ###################################################
  133 function viewaddWaitLink()
  134 {
  135     global $start_script, $start_script_t, $_GET, $tpl;
  136     global $config, $mylink;
  137     
  138     if (isset ($_GET["category"]) && $_GET["category"] < 0)
  139     {
  140         $_GET["category"] = 0;
  141     }
  142     if (! isset ($_GET["category"]))
  143     {
  144         $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category order by pathto");
  145     } else {
  146         $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat=\"".intval($_GET[category])."\" or under=\"".intval($_GET[category])."\" order by pathto");
  147     }
  148 
  149     $options = "";          
  150     while ($info_c = mysqli_fetch_array($category) )
  151     {
  152     
  153         $patharray = explode(":",$info_c["pathto"]);
  154         $options .= "<option value=\"$info_c[cat]\">";
  155         while (list($key, $val)=each($patharray))
  156         {
  157             if ($val != ""){
  158                 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
  159                 $sub_title_new = mysqli_fetch_array($result_sub);
  160                 $options .= "/$sub_title_new[title]";
  161             }
  162                     
  163         }
  164         $options .= "</option>\n";
  165     }
  166 
  167     $tpl->set_file("newlink", "form_update_link.tpl");
  168     $tpl->set_block("newlink", "delete_row", "deleteme");
  169     
  170     # security code
  171     if ($config{'security_code'} != "" && getuser() != "admin") {
  172         $secret = ImageGenSecret(8);
  173         $ref = ImageGenSecretRef($secret);
  174         $tpl->set_var ("IMG_SECURITY_LINK", "<img src='".$start_script_t."sec_img=".$ref."'>");
  175         $tpl->set_var ("SECURITY", "$ref");     
  176     } else {
  177         # delete security bloc
  178         $tpl->set_block ("newlink", "security_row", "deleteme");
  179     }
  180     
  181     $tpl->set_var( array(
  182                  "ACTION" => $start_script_t."mode=add_link",
  183                  "SUBMIT_NAME" => "add_wait_link",
  184                  "OPTIONS" => "$options",
  185                  "LINK" => "http://",
  186                  "IDX" => ""
  187                  ));
  188     $content = $tpl->subst("newlink");
  189     
  190     return $content;
  191 }
  192 
  193 ###################################################
  194 # Add a category in the waiting queue
  195 ###################################################
  196 function viewaddWaitcategory()
  197 {
  198     global $start_script, $start_script_t, $_GET, $tpl;
  199     global $config, $mylink;
  200 
  201     if (isset ($_GET["category"]) && $_GET["category"] < 0)
  202     {
  203         $_GET["category"] = 0;
  204     }
  205     
  206 
  207     $tpl->set_file("newcat", "form_new_cat.tpl");
  208     $tpl->set_var("ACTION" , $start_script_t."mode=add_category");
  209          
  210     if (isset ($_GET["category"])){
  211         $getcat = intval($_GET["category"]);
  212         $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$getcat' or under='$getcat' order by pathto");
  213         $options = "";
  214         while ($info_c = mysqli_fetch_array($category) )
  215         {
  216     
  217             $patharray = explode(":",$info_c["pathto"]);
  218             $options .= "<option value=\"$info_c[cat]\">";
  219             while (list($key, $val)=each($patharray))
  220             {
  221                 if ($val != "") {
  222                     $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
  223                     $sub_title_new = mysqli_fetch_array($result_sub);
  224                     $options .= "/$sub_title_new[title]";
  225                 }       
  226             }
  227             $options .= "</option>\n";      
  228         }   
  229         $tpl->set_var( "OPTIONS" , "$options" );
  230     } else {
  231         # remove a row from the template
  232         $tpl->set_block("newcat", "cat_select", "deleteme");
  233         $tpl->set_var("deleteme" , "");
  234     }
  235     
  236     $content = $tpl->subst("newcat");
  237     
  238     return $content;
  239 }
  240 
  241 ###################################################
  242 #
  243 ###################################################
  244 function doaddWaitcategory($_unused)
  245 {
  246     global $linkbackurl;
  247     global $config, $_POST, $mylink;
  248         
  249     if ($_POST["title"] == ''){
  250         $error = Message ("forgot_title");
  251     }
  252 
  253     # reject the submit if some fields contain unwanted data
  254     if ($config['spam_filter'] > 0 && getuser() != "admin") {
  255         if (preg_match("/http:\/\//i", $_POST["title"].$_POST["message"])) {
  256             # do not display a nice error message ;-)
  257             $error .= Message("error_security_code");
  258         }
  259     }
  260 
  261     if (! isset($error))
  262     {
  263         while(list($key,$data)=each($_POST))
  264         {
  265             $_POST[$key] = htmlspecialchars($_POST[$key]);
  266         }
  267         
  268         $id=time();srand($id);$id += rand();
  269         $ip_addy=getenv("REMOTE_ADDR");
  270 
  271         if ($config["adminemail"] != "") {
  272             mymail($config["adminemail"], Message("link_submitted").":".htmlentities($_POST[title]), Message("link_submitted_message"), $config["fromemail"]);
  273             
  274         $su = mysqli_query($mylink, "insert into ".$config["pre"]."waitcat (id,title,message,cat,ip) values('$id',
  275                     '$_POST[title]' ,
  276                     '$_POST[message]' ,
  277                     '$_POST[category]' ,
  278                     '$ip_addy' 
  279                 )") or die (mysqli_error($mylink));
  280         
  281         $content .= Message ("thanks_submit",
  282                      array ("LINK" => "$linkbackurl"));
  283     
  284         }
  285     } else {
  286         $content = Message ("error_submit",
  287                     array ("ERROR" => "$error"));
  288     }
  289 
  290 
  291     return $content;
  292 }
  293 
  294 #####################
  295 #
  296 #  This is the main code for above text....
  297 #
  298             
  299             if(isset($_POST["add_wait_link"]) and $allow["a_link"] == 1)
  300             {
  301                 $content = doaddWaitLink($_POST);
  302     
  303                 $tpl->set_var( array( 
  304                     "CATEGORY_TITLE" => Message ("add_new_link"),
  305                     "CONTENT" => $content
  306                 ));
  307                 showStartTemplate();            
  308             }
  309             
  310             elseif (isset($_POST["add_wait_category"]) and $allow["a_category"] == 1)
  311             {
  312                 $content = doaddWaitcategory($_POST);
  313                 
  314                 $tpl->set_var( array( 
  315                     "CATEGORY_TITLE" => Message ("add_new_cat"),
  316                     "CONTENT" => $content 
  317                 ));
  318                 showStartTemplate();
  319             }           
  320             elseif (isset($_POST["update_link"]) and $allow["u_link"] == 1 )
  321             {
  322             
  323                 $content = doaddWaitLink($_POST);
  324                 
  325                 $tpl->set_var( array( 
  326                     "CATEGORY_TITLE" => Message ("update_link"),
  327                     "CONTENT" => $content 
  328                     ));
  329                 showStartTemplate();                    
  330             
  331             }
  332             elseif ($_GET["mode"] == 'add_link' and $allow["a_link"] == 1)
  333             {
  334                 No_Search_Footer();
  335 
  336                 $content = viewaddWaitLink();
  337                         
  338                 $tpl->set_var( array( 
  339                     "CATEGORY_TITLE" => Message ("add_new_link"),
  340                     "CONTENT" => $content
  341                     ));
  342                 showStartTemplate();
  343             }
  344             elseif ($_GET["mode"] == 'add_category' and $allow["a_category"] == 1)
  345             {
  346                 No_Search_Footer();
  347 
  348                 $content = viewaddWaitCategory();
  349                         
  350                 $tpl->set_var( array( 
  351                     "CATEGORY_TITLE" => Message ("add_new_cat"),
  352                     "CONTENT" => $content 
  353                     ));
  354                 showStartTemplate();
  355             }           
  356             elseif ($_GET["mode"] == 'update_link' and $allow["u_link"] == 1)
  357             {
  358                 
  359                 No_Search_Footer();
  360 
  361                 if (isset($_GET["link"]))
  362                 {
  363                 $content = viewULink($_GET);
  364                 }
  365                 else
  366                 {
  367                 $content = whatUlink();
  368                 }
  369                 
  370                 $tpl->set_var( array( 
  371                     "CATEGORY_TITLE" => Message ("update_link"),
  372                     "CONTENT" => $content 
  373                     ));
  374                 showStartTemplate();
  375             }
  376             else
  377             {
  378                 No_Search_Footer();
  379                 $tpl->set_var("CONTENT" , Message ("seem_to_be_lost"));
  380                 showStartTemplate();
  381             }
  382 ?>