Location: PHPKode > projects > Tiger Php News System > tigerPhpNewsSystem/plugins/batchadd.php
<?
    /*
     * This software is part of the Tiger php news system
     * http://tpns.k-na.se
     * 
     * This software comes with ABSOLUTELY NO WARRANTY. For details, see
     * the enclosed file COPYING for license information (GPL). If you
     * did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
     * 
     */
    class batchadd
    {
        //{{{ Batch add news
        function batchadd()
        {
            require_once( 'Main.php' );
        }
        //}}}
        //{{{ getAccess
        function getAccess()
        {
            return "3";
        }
        //}}}
        //{{{getName
        function getName()
        {
            return "Batch add news";
        }
        //}}}
        //{{{execute
        function execute($main)
        {
            $role=$_SESSION['role'];
            $userid=$_SESSION['userid'];
            $text=$_SESSION['text'];
            $requestid=$_SESSION['reqid'];
            $defaultnewsaccess="0";
            $initpage=false;
            $upload_max_filesize = ini_get('upload_max_filesize');
            $form_upload_max_filesize = preg_replace('/M/', '000000', $upload_max_filesize);
            $text_upload_max_filesize = preg_replace('/M/', ' Megabyte(s)', $upload_max_filesize);
            if(isset($_REQUEST['do'] ))
            {
            //{{{ Add news
                if ( $_REQUEST['do'] == "addnews" and "$role" != "0" )
                {
                    $addnews=true;
                    $img="";
                    $access="";if ( $_REQUEST['access'] != "" ){$access=$_REQUEST['access'];}else{$addnews=false;}
                    $owner=$userid;
                    $headline="";if ( $_REQUEST['header'] != "" ){$headline=$_REQUEST['header'];}else{$addnews=false;}
                    $order="";if ( $_REQUEST['order'] != "" ){$order=$_REQUEST['order'];}else{$order="1";}
                    $type="";if ( $_REQUEST['type'] != "" ){$type=$_REQUEST['type'];}else{$type="1";}
                    $data="";if ( $_REQUEST['news'] != "" ){$data=$_REQUEST['news'];}else{$addnews=false;}
                    $data2="";if ( $_REQUEST['extnews'] != "" ){$data2=$_REQUEST['extnews'];}
                    $category="1";
                    if ( $_REQUEST['newcategory'] != "" ){
                        $newcat=$main->addCategory($_REQUEST['newcategory']);
                        if ( isset($newcat->lastid) and $newcat->lastid != 0)
                        {
                            $category=$newcat->lastid;
                        }
                    }
                    elseif($_REQUEST['category'] != "" ){$category=$_REQUEST['category'];}
                    else{$addnews=false;}
                    $newsadded="";
                    if ( $addnews )
                    {
                        $extractdir="./img/tmp/".session_id()."";
                        $main->mkdirr($extractdir);
                        include('pclzip.lib.php');
                        $archive = new PclZip($_FILES['img']['tmp_name']);
                        $archive->extract(PCLZIP_OPT_PATH, $extractdir);
                        $d=dir($extractdir);
                        while($entry = $d->read())
                        {   
                            $filename=$entry;
                            if( is_file("$extractdir/$entry"))

                            {
                                if (getimagesize("$extractdir/$entry"))
                                {
                                    $filename=str_replace("å","a",$filename);
                                    $filename=str_replace("ä","a",$filename);
                                    $filename=str_replace("ö","o",$filename);
                                    $filename=str_replace("Å","A",$filename);
                                    $filename=str_replace("Ä","A",$filename);
                                    $filename=str_replace("Ö","O",$filename);
                                    $filename=str_replace("(","_",$filename);
                                    $filename=str_replace(")","_",$filename);
                                    $filename=ereg_replace("[^a-z,A-Z,0-9,_,.]","_",$filename);
                                    $file=Array();
                                    $file['name']="$filename";
                                    $file['tmp_name']="$extractdir/$entry";

                                    $result = $main->addnews( $access, $owner, $headline, $filename, $data, $data2, $order, $category, $type );
                                    $filename=$main->uploadfile( $file, "news", $result->lastid );
                                    $newsadded.="<a href='?page=viewnews&amp;id=".$result->lastid."'>$filename</a><br />";
                                }
                            }
                        }
                        $main->rmdirr($extractdir);
                        print "$newsadded";
                    }
                }
    unset($access, $owner, $headline, $filename, $data, $data2, $order, $category, $type);

                }
        //}}}
            
            else
            {
//{{{New news
            $defaultnewstext="";
            $bbcode=$main->bbcode;
            print "<script type='text/javascript'>
                function validate(form)
                {
                    error=\"\";
                    if ( form.header.value == \"\" )
                    {
                        error=\"".str_replace(":",","," ".$main->edit_array( $text['header'])." ")."\";
                    }

                    if ( form.news.value == \"\" )
                    {
                        error=error+\"".str_replace(":",""," ".$main->edit_array( $text['newstext'])." ")."\";
                    }
                    if (error != '' )
                    {
                        error=error.replace(\":\", \",\");
                        alert('".$main->edit_array( $text['missingfields'])."'+' '+error);
                        return;
                    }
                    else
                    {
                        form.submit();
                    }
                }
            </script>";

            print "<form enctype='multipart/form-data' action='?page=plugin&amp;plug=batchadd&amp;do=addnews' method='post'><p><input type='hidden' name='rid' value='$requestid' /></p>\n";
            print "<table summary='New news'>\n";
            print "<tr><td colspan='3'><span class=\"headline\"><b>Batch add news</b></span></td></tr>\n";
            print "<tr><td>$text[access]</td><td> <select name='access'>\n";
            if ( "$defaultnewsaccess" == "0" ){$selected="selected='selected'";}else{$selected="";}if ( $role >= "3" or ($allowuserstoaddannonnews and $role >= "1" ) ){print "<option $selected value='0'>$text[access0]</option>\n";}
                if ( "$defaultnewsaccess" == "1" ){$selected="selected='selected'";}else{$selected="";}if ( $role >= "3" or ($allowuserstoaddannonnews and $role >= "1" ) ){print "<option $selected value='1'>$text[access1]</option>\n";}
                    if ( "$defaultnewsaccess" == "2" ){$selected="selected='selected'";}else{$selected="";}if ( $role >= "2" ){print "<option $selected value='2'>$text[access2]</option>\n";}
                    if ( "$defaultnewsaccess" == "3" ){$selected="selected='selected'";}else{$selected="";}if ( $role >= "3" ){print "<option $selected value='3'>$text[access3]</option>\n";}
                    if ( "$defaultnewsaccess" == "4" ){$selected="selected='selected'";}else{$selected="";}if ( $role >= "4" ){print "<option $selected value='4'>$text[access4]</option>\n";}
                    print "</select></td></tr>\n";
                    if ( "$role" >= "3" )
                    {
                        print "<tr><td>$text[sticky]</td><td> <select name='order'>\n";
                        print "<option value='1'>$text[sticky1]</option>\n";
                        print "<option value='0'>$text[sticky0]</option>\n";
                        print "</select></td></tr>\n";
                    }
                    print "<tr><td>$text[newstype]</td><td> <select name='type'>\n";
                    if ( $role >= "2" ){print "<option value='1'>$text[type1]</option>\n";}
                    if ( $role >= "2" ){print "<option value='2'>$text[type2]</option>\n";}
                    if ( $role >= "1" ){print "<option value='5'>$text[type5]</option>\n";}
                    if ( $role >= "1" ){print "<option value='6'>$text[type6]</option>\n";}
                    if ( $role >= "3" ){print "<option value='7'>$text[type7]</option>\n";}
                    if ( $role >= "3" ){print "<option value='8'>$text[type8]</option>\n";}
                    if ( $role >= "2" ){print "<option value='9'>$text[type9]</option>\n";}

                    print "</select></td></tr>\n";
                    $category = $main->getAllCategories();
                    print "<tr><td>$text[category]</td><td> <select name='category'>\n";
                    foreach( $category->records as $item )
                    {                                                                                                                                                                                      
                        $catitem=str_replace(" ","&nbsp;",$item['name']);
                        if ( isset($text[$item['name']])){$catitem=str_replace(" ","&nbsp;",$text[$item['name']]);}
                        print "<option value='$item[id]'>$catitem</option>\n";
                    }
                    print "</select><input name='newcategory' type='text' id='newcategory'/></td></tr>\n";
                    if ( $role >= "2" ){
                        print "<tr><td>$text[image]</td><td> 
                                <input type='file' id='img' name='img'/> Only ZIP file. $text[maxfilesize] $text_upload_max_filesize
                                <input type='hidden' name='MAX_FILE_SIZE' value='$form_upload_max_filesize' /></td></tr>\n";}
                        print "<tr><td>$text[header]</td><td><input name='header' type='text' id='header'/></td></tr>\n";
                        print "<tr><td colspan='2'>$text[newstext]</td></tr>\n";
                        print "<tr><td colspan='2'><textarea name='news' rows='20' cols='60'>$defaultnewstext</textarea></td></tr>\n";
                        print "<tr><td colspan='2'>$text[extnewstext]</td></tr>\n";
                        print "<tr><td colspan='2'><textarea name='extnews' rows='20' cols='60'></textarea></td></tr>\n";
                        print "<tr><td colspan='2'><input type='button' value='$text[addnews]' id='addnews' onclick=\"validate(this.form)\"  class='button'/> <input type='reset' value='$text[reset]' class='button'/></td></tr>\n";
                            print "</table></form>\n";
                        print "$bbcode";
            }
                    //}}}
            }
                    //}}}
    }
?>
Return current item: Tiger Php News System