/e107_plugins/download/handlers/adminDownload_class.php
PHP | 2205 lines | 32 code | 38 blank | 2135 comment | 4 complexity | df1862f896611f82b866b3129d5a19ba MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * e107 website system
- *
- * Copyright (C) 2008-2009 e107 Inc (e107.org)
- * Released under the terms and conditions of the
- * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
- *
- *
- *
- * $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $
- * $Revision$
- * $Date$
- * $Author$
- */
- if (!e107::isInstalled('download')) { exit(); }
- require_once(e_PLUGIN.'download/handlers/download_class.php');
- require_once(e_HANDLER.'upload_handler.php');
- require_once(e_HANDLER.'xml_class.php');
- class adminDownload extends download
- {
- var $searchField;
- var $advancedSearchFields;
- var $userclassOptions;
- function adminDownload()
- {
- global $pref;
- parent::download();
- $this->userclassOptions = 'blank,nobody,guest,public,main,admin,member,classes';
- // Save basic search string
- if (isset($_POST['download-search-text']))
- {
- $this->searchField = $_POST['download-search-text'];
- }
- // Save advanced search criteria
- if (isset($_POST['download_advanced_search_submit']))
- {
- $this->advancedSearchFields = $_POST['download_advanced_search'];
- }
- }
-
- /*
- function show_filter_form($action, $subAction, $id, $from, $amount)
- {
- global $e107, $mySQLdefaultdb, $pref, $user_pref;
- $frm = new e_form();
-
- $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class"));
- // $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123));
- $url = "admin_download.php";
-
- // Search field
- $text .= "
- <script type='text/javascript'>
- </script>
- <form method='post' action='".e_SELF."' class='e-show-if-js e-filter-form' id='jstarget-downloads-list'>
- <div id='download_search'>
- <fieldset>
- <legend class='e-hideme'>".DOWLAN_194."</legend>
- <table class='adminlist'>
- <tr>
- <td>".DOWLAN_198." ".$frm->text('download-search-text', $this->searchField, 50, array('size'=>50, 'class' => 'someclass'))." <a href='#download_search#download_advanced_search' class='e-swapit'>Switch to Advanced-Search</a></td>
- </tr>
- </table>
-
- ";
- // Filter should use ajax to filter the results automatically after typing.
-
- // $text .= "
- // <div class='buttons-bar center'>
- // <button type='submit' class='update' name='download_search_submit' value='no-value'><span>".DOWLAN_51."</span></button>
- // <br/>
-
- // </div>";
- $text.= "
- </fieldset>
- </div>
- </form>
- ";
- // Advanced search fields
- $text .= "
- <form method='post' action='".e_SELF."'>
- <div id='download_advanced_search' class='e-hideme'>
- <fieldset>
- <legend class='e-hideme'>".DOWLAN_183."</legend>
- <table class='adminform'>
- <colgroup>
- <col style='width:15%;'/>
- <col style='width:35%;'/>
- <col style='width:15%;'/>
- <col style='width:35%;'/>
- </colgroup>
- <tr>
- <td>".DOWLAN_12."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[name]' size='30' value='{$this->advancedSearchFields['name']}' maxlength='50'/></td>
- <td>".DOWLAN_18."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[description]' size='50' value='{$this->advancedSearchFields['description']}' maxlength='50'/></td>
- </tr>
- <tr>
- <td>".DOWLAN_11."</td>
- <td>".$this->getCategorySelectList($this->advancedSearchFields['category'], true, false, ' ', 'download_advanced_search[category]');
- $text .= " </td>
- <td>".DOWLAN_149."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[url]' size='50' value='{$this->advancedSearchFields['url']}' maxlength='50'/></td>
- </tr>
- <tr>
- <td>".DOWLAN_182."</td>
- <td>
- ";
- $text .= $this->_getConditionList('download_advanced_search[date_condition]', $this->advancedSearchFields['date_condition']);
- //TODO $text .= $frm->datepicker('download_advanced_search[date]', $this->advancedSearchFields['date']);
- $text .= "//TODO";
- $text .= "
- </td>
- <td>".DOWLAN_21."</td>
- <td>
- <select name='download_advanced_search[status]' class='tbox'>";
- $text .= $this->_getStatusList('download_advanced_search[status]', $this->advancedSearchFields['status']);
- $text .= " </select>
- </td>
- </tr>
- <tr>
- <td>".DOWLAN_66."</td>
- <td>
- ";
- $text .= $this->_getConditionList('download_advanced_search[filesize_condition]', $this->advancedSearchFields['filesize_condition']);
- $text .= "
- <input class='tbox' type='text' name='download_advanced_search[filesize]' size='10' value='{$this->advancedSearchFields['filesize']}'/>
- <select name='download_advanced_search[filesize_units]' class='tbox'>
- <option value='1' ".($this->advancedSearchFields['filesize_units'] == '' ? " selected='selected' " : "")." >b</option>
- <option value='1024' ".($this->advancedSearchFields['filesize_units'] == '1024' ? " selected='selected' " : "")." >Kb</option>
- <option value='1048576' ".($this->advancedSearchFields['filesize_units'] == '1048576' ? " selected='selected' " : "")." >Mb</option>
- </select>
- </td>
- <td>".DOWLAN_43."</td>
- <td>".$frm->uc_select('download_advanced_search[visible]', $this->advancedSearchFields['visible'], $this->userclassOptions)."</td>
- </tr>
- <tr>
- <td>".DOWLAN_29."</td>
- <td>
- ";
- $text .= $this->_getConditionList('download_advanced_search[requested_condition]', $this->advancedSearchFields['requested_condition']);
- $text .= " <input class='tbox' type='text' name='download_advanced_search[requested]' size='6' value='{$this->advancedSearchFields['requested']}' maxlength='6'/> times
- </td>
- <td>".DOWLAN_113."</td>
- <td>
- ";
- $text .= $frm->uc_select('download_advanced_search[class]', $this->advancedSearchFields['class'], $this->userclassOptions);
- $text .= "
- </td>
- </tr>
- <tr>
- <td>".DOWLAN_15."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[author]' size='30' value='{$this->advancedSearchFields['author']}' maxlength='50'/></td>
- <td>".DOWLAN_16."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[author_email]' size='30' value='{$this->advancedSearchFields['author']}' maxlength='50'/></td>
- </tr>
- <tr>
- <td>".DOWLAN_17."</td>
- <td><input class='tbox' type='text' name='download_advanced_search[author_website]' size='30' value='{$this->advancedSearchFields['author']}' maxlength='50'/></td>
- <td> </td>
- <td> </td>
- </tr>
- </table>
- <div class='buttons-bar center'>
- <span class='e-show-if-js f-left'><a href='#download_advanced_search#download_search' class='e-swapit'>Simple search</a></span>
- <button type='submit' class='update' name='download_advanced_search_submit' value='no-value'><span>".DOWLAN_51."</span></button>
- </div>
- </fieldset>
- </div>
- </form>";
-
- return $text;
- }
- */
-
-
-
- /*
-
-
- function show_existing_items($action, $subAction, $id, $from, $amount)
- {
- global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref, $user_pref;
- $frm = new e_form();
- $sortorder = $subAction ? $subAction : $pref['download_order'];
- $sortdirection = $id=="asc" ? "asc" : "desc";
- $amount = 10;
- if(!$sortorder)
- {
- $sortorder = "download_id";
- }
- $sort_link = $sortdirection == 'asc' ? 'desc' : 'asc';
- $columnInfo = array(
- "checkboxes" => array("title" => "", "forced"=> TRUE, "width" => "3%", "thclass" => "center first", "toggle" => "dl_selected"),
- "download_id" => array("title"=>DOWLAN_67, "type"=>"", "width"=>"auto", "thclass"=>"", "forced"=>true),
- "download_name" => array("title"=>DOWLAN_12, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_url" => array("title"=>DOWLAN_13, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_author" => array("title"=>DOWLAN_15, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_author_email" => array("title"=>DOWLAN_16, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_author_website" => array("title"=>DOWLAN_17, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_description" => array("title"=>DOWLAN_18, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_filesize" => array("title"=>DOWLAN_66, "type"=>"", "width"=>"auto", "thclass"=>"right"),
- "download_requested" => array("title"=>DOWLAN_29, "type"=>"", "width"=>"auto", "thclass"=>"center"),
- "download_category" => array("title"=>DOWLAN_11, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_active" => array("title"=>DOWLAN_21, "type"=>"", "width"=>"auto", "thclass"=>"center"),
- "download_datestamp" => array("title"=>DOWLAN_182, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_thumb" => array("title"=>DOWLAN_20, "type"=>"", "width"=>"auto", "thclass"=>"center"),
- "download_image" => array("title"=>DOWLAN_19, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_comment" => array("title"=>DOWLAN_102, "type"=>"", "width"=>"auto", "thclass"=>"center"),
- "download_class" => array("title"=>DOWLAN_113, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_mirror" => array("title"=>DOWLAN_128, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_mirror_type" => array("title"=>DOWLAN_195, "type"=>"", "width"=>"auto", "thclass"=>""),
- "download_visible" => array("title"=>DOWLAN_43, "type"=>"", "width"=>"auto", "thclass"=>""),
- "options" => array("title"=>LAN_OPTIONS, "width"=>"10%", "thclass"=>"center last", "forced"=>true)
- );
-
- $filterColumns = ($user_pref['admin_download_disp']) ? $user_pref['admin_download_disp'] : array("download_name","download_class");
- $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc. download_category_id=d.download_category";
-
- if ($this->searchField) {
- $where = array();
- array_push($where, "download_name REGEXP('".$this->searchField."')");
- array_push($where, "download_description REGEXP('".$this->searchField."')");
- array_push($where, "download_author REGEXP('".$this->searchField."')");
- array_push($where, "download_author_email REGEXP('".$this->searchField."')");
- array_push($where, "download_author_website REGEXP('".$this->searchField."')");
- $where = " WHERE ".implode(" OR ", $where);
- $query .= "$where ORDER BY {$sortorder} {$sortdirection}";
- }
- else if ($this->advancedSearchFields) {
- $where = array();
- if (strlen($this->advancedSearchFields['name']) > 0) {
- array_push($where, "download_name REGEXP('".$this->advancedSearchFields['name']."')");
- }
- if (strlen($this->advancedSearchFields['url']) > 0) {
- array_push($where, "download_url REGEXP('".$this->advancedSearchFields['url']."')");
- }
- if (strlen($this->advancedSearchFields['author']) > 0) {
- array_push($where, "download_author REGEXP('".$this->advancedSearchFields['author']."')");
- }
- if (strlen($this->advancedSearchFields['description']) > 0) {
- array_push($where, "download_description REGEXP('".$this->advancedSearchFields['description']."')");
- }
- if (strlen($this->advancedSearchFields['category']) != 0) {
- array_push($where, "download_category=".$this->advancedSearchFields['category']);
- }
- if (strlen($this->advancedSearchFields['filesize']) > 0) {
- array_push($where, "download_filesize".$this->advancedSearchFields['filesize_condition'].($this->advancedSearchFields['filesize']*$this->advancedSearchFields['filesize_units']));
- }
- if ($this->advancedSearchFields['status'] != 99) {
- array_push($where, "download_active=".$this->advancedSearchFields['status']);
- }
- if (strlen($this->advancedSearchFields['date']) > 0) {
- switch ($this->advancedSearchFields['date_condition']) {
- case "<=" :
- {
- array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].($this->advancedSearchFields['date']+86400));
- break;
- }
- case "=" :
- {
- array_push($where, "(download_datestamp>=".$this->advancedSearchFields['date']." AND download_datestamp<=".($this->advancedSearchFields['date']+86399).")");
- break;
- }
- case ">=" :
- {
- array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].$this->advancedSearchFields['date']);
- break;
- }
- }
- }
- if (strlen($this->advancedSearchFields['requested']) > 0) {
- array_push($where, "download_requested".$this->advancedSearchFields['requested_condition'].$this->advancedSearchFields['requested']);
- }
- if ($this->advancedSearchFields['visible']) {
- array_push($where, "download_visible=".$this->advancedSearchFields['visible']);
- }
- if ($this->advancedSearchFields['class']) {
- array_push($where, "download_class=".$this->advancedSearchFields['class']);
- }
- $where = (count($where) > 0 ? " WHERE ".implode(" AND ", $where) : "");
-
- $query .= "$where ORDER BY {$sortorder} {$sortdirection}";
- }
- else
- {
- $query .= " ORDER BY ".($subAction ? $subAction : $sortorder)." ".($id ? $id : $sortdirection)." LIMIT $from, $amount";
- }
-
- $text .= "<fieldset id='downloads-list'><legend class='e-hideme'>".DOWLAN_7."</legend>";
- if ($dl_count = $sql->db_Select_gen($query))
- {
- $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")."
- <table class='adminlist'>
- ".$frm->colGroup($columnInfo,$filterColumns)
- .$frm->thead($columnInfo,$filterColumns,"main.[FIELD].[ASC].[FROM]")."
- <tbody>
- ";
-
- $rowStyle = "even";
-
- while ($row = $sql->db_Fetch())
- {
- $mirror = strlen($row['download_mirror']) > 0;
- $text .= "<tr>\n
- <td class='center'>".$frm->checkbox("dl_selected[".$row["download_id"]."]", $row['download_id'])."</td>
- <td>".$row['download_id']."</td>\n";
-
- // Display Chosen options
-
- foreach($filterColumns as $disp)
- {
-
- switch ($disp)
- {
- case "download_name" :
- $text .= "<td>";
- $text .= "<a href='".e_PLUGIN."download/download.php?view.".$row['download_id']."'>".$tp->toHTML($row['download_name'])."</a>";
- break;
- case "download_category" :
- $text .= "<td>";
- $text .= $tp->toHTML($row['download_category_name']);
- break;
- case "download_datestamp" :
- global $gen;
- $text .= "<td>";
- $text .= ($row[$disp]) ? $gen->convert_date($row[$disp],'short') : "";
- break;
- case "download_class" :
- case "download_visible" :
- $text .= "<td>";
- $text .= r_userclass_name($row[$disp])." ";
- break;
- case "download_filesize" :
- $text .= "<td class='right'>";
- //$text .= ($row[$disp]) ? $this->e107->parseMemorySize(($row[$disp])) : "";
- $text .= ($row[$disp]) ? (intval($row[$disp])) : "";
- break;
- case "download_thumb" :
- $text .= "<td>";
- $text .= ($row[$disp]) ? "<img src='".e_FILE."downloadthumbs/".$row[$disp]."' alt=''/>" : "";
- break;
- case "download_image" :
- $text .= "<td>";
- $text .= "<a rel='external' href='".e_FILE."downloadimages/".$row[$disp]."' >".$row[$disp]."</a>";
- break;
- case "download_description" :
- $text .= "<td>";
- $text .= $tp->toHTML($row[$disp],TRUE);
- break;
- case "download_active" :
- $text .= "<td class='center'>";
- if ($row[$disp]== 1)
- {
- $text .= "<img src='".ADMIN_TRUE_ICON_PATH."' title='".DOWLAN_123."' alt='' style='cursor:help'/>";
- }
- elseif ($row[$disp]== 2)
- {
- $text .= "<img src='".ADMIN_WAR/NING_ICON_PATH."' title='".DOWLAN_124."' alt='' style='cursor:help'/>";
- }
- else
- {
- $text .= "<img src='".ADMIN_FALSE_ICON_PATH."' title='".DOWLAN_122."' alt='' style='cursor:help'/>";
- }
- break;
- case "download_comment" :
- $text .= "<td class='center'>";
- $text .= ($row[$disp]) ? ADMIN_TRUE_ICON : "";
- break;
- case "download_mirror" :
- $text .= "<td>";
- $mirrorArray = $this->makeMirrorArray($row[$disp], TRUE);
- foreach($mirrorArray as $mirror) {
- $title = DOWLAN_66." ".$mirror['filesize']."; ".DOWLAN_29." ".$mirror['requests'];
- $text .= "<div><img src='".ADMIN_INFO_IC/ON_PATH."' title='".$title."' alt='' style='cursor:help'/> ";
- $text .= $tp->toHTML($mirror['url']).'</div>';
- }
- break;
- case "download_mirror_type" :
- $text .= "<td class='center'>";
- if ($mirror)
- {
- switch ($row[$disp])
- {
- case 1:
- $text .= DOWLAN_196;
- break;
- default:
- $text .= DOWLAN_197;
- }
- }
- break;
- case "download_requested" :
- case "download_active" :
- case "download_thumb" :
- case "download_comment" :
- $text .= "<td class='center'>";
- $text .= $tp->toHTML($row[$disp]);
- break;
- default :
- $text .= "<td>";
- $text .= $tp->toHTML($row[$disp]);
- }
- $text .= "</td>";
- }
-
- $text .= "
- <td class='center'>
- <a href='".e_SELF."?create.edit.".$row['download_id']."'>".ADMIN_EDIT_ICON."</a>
- <input type='image' title='".LAN_DELETE."' name='delete[main_".$row['download_id']."]' src='".ADMIN_DELETE_ICON_PATH."' onclick=\"return jsconfirm('".$tp->toJS(DOWLAN_33." [ID: ".$row['download_id']." ]")."') \"/>
- </td>
- </tr>";
- }
- $text .= "</tbody></table>";
- // $text .= "";
- }
- else
- { // 'No downloads yet'
- $text .= "<div style='text-align:center'>".DOWLAN_6."</div>";
- }
-
- // Next-Previous.
- $downloads = $sql->db_Count("download");
- if ($downloads > $amount && !$this->searchFields && !$this->advancedSearchFields)
- {
- $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]";
- $text .= "<div class='buttons-bar center nextprev'>".$this->batch_options().
- $tp->parseTemplate("{NEXTPREV={$parms}}")."</div>";
- }
-
- $text .= "</form></fieldset>";
-
- return $text;
- }
- */
-
- // ---------------------------------------------------------------------------
-
- /*
-
- function batch_options()
- {
- $frm = new e_form();
- $classes = get_userclass_list();
- return $frm->batchoptions(
- array('delete_selected'=>LAN_DELETE),
- array(
- 'userclass' =>array('Assign userclass...',$classes),
- 'visibility'=>array('Assign Visibility..',$classes)
- )
- );
- }
- function _observe_processBatch()
- {
- list($type,$tmp,$uclass) = explode("_",$_POST['execute_batch']);
- $method = "batch_".$type;
- if ((method_exists($this,$method) || $type='visibility') && isset ($_POST['dl_selected']))
- {
- if($type=='userclass' || $type=='visibility')
- {
- $mode = ($type=='userclass') ? 'download_class' : 'download_visible';
- $this->batch_userclass($_POST['dl_selected'],$uclass,$mode);
- }
- else
- {
- $this->$method($_POST['dl_selected']);
- }
- }
- }
-
- function batch_userclass($download_ids,$uclass,$mode='download_class')
- {
- $emessage = &eMessage::getInstance();
- if(e107::getDb() -> db_Update("download", $mode." ='{$uclass}' WHERE download_id IN (".implode(",",$download_ids).") "))
- {
- $emessage->add("It Worked", E_MESSAGE_SUCCESS);
- }
- else
- {
- $emessage->add("It Failed", E_MESSAGE_ERROR);
- }
- }*/
-
- // Given the string which is stored in the DB, turns it into an array of mirror entries
- // If $byID is true, the array index is the mirror ID. Otherwise its a simple array
- /*
- function makeMirrorArray($source, $byID = FALSE)
- {
- $ret = array();
- if ($source)
- {
- $mirrorTArray = explode(chr(1), $source);
- $count = 0;
- foreach($mirrorTArray as $mirror)
- {
- if ($mirror)
- {
- list($mid, $murl, $mreq, $msize) = explode(",", $mirror);
- $ret[$byID ? $mid : $count] = array('id' => $mid, 'url' => $murl, 'requests' => $mreq, 'filesize' => $msize);
- $count++;
- }
- }
- }
- return $ret;
- }
- */
- /*
- // Turn the array into a string which can be stored in the DB
- function compressMirrorArray($source)
- {
- if (!is_array($source) || !count($source)) return '';
- $inter = array();
- foreach ($source as $s)
- {
- $inter[] = $s['id'].','.$s['url'].','.$s['requests'].','.$s['filesize'];
- }
- return implode(chr(1),$inter);
- }*/
- /*
- function create_download($subAction='', $id='')
- {
- global $download, $e107, $cal, $tp, $sql, $fl, $rs, $ns, $file_array, $image_array, $thumb_array;
- require_once(e_PLUGIN.'download/download_shortcodes.php');
- require_once(e_HANDLER."form_handler.php");
- if ($file_array = $fl->get_files(e_DOWNLOAD, "","standard",5))
- {
- sort($file_array);
- }
- if ($public_array = $fl->get_files(e_UPLOAD))
- {
- foreach($public_array as $key=>$val)
- {
- $file_array[] = str_replace(e_UPLOAD,"",$val);
- }
- }
- */
- /* if ($sql->db_Select("rbinary")) //TODO Remove me.
- {
- while ($row = $sql->db_Fetch())
- {
- extract($row);
- $file_array[] = "Binary ".$binary_id."/".$binary_name;
- }
- }
- */
- /*
- if ($image_array = $fl->get_files(e_FILE.'downloadimages/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2))
- {
- sort($image_array);
- }
- if ($thumb_array = $fl->get_files(e_FILE.'downloadthumbs/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2))
- {
- sort($thumb_array);
- }
- $frm = new e_form();
- $mirrorArray = array();
- $download_status[0] = DOWLAN_122;
- $download_status[1] = DOWLAN_123;
- $download_status[2] = DOWLAN_124;
- if (!$sql->db_Select("download_category"))
- {
- $ns->tablerender(ADLAN_24, "<div style='text-align:center'>".DOWLAN_5."</div>");
- return;
- }
- $download_active = 1;
- if ($_GET['action'] == "edit" && !$_POST['submit'])
- {
- if ($sql->db_Select("download", "*", "download_id=".intval($_GET['id'])))
- {
- $row = $sql->db_Fetch();
- extract($row);
- $mirrorArray = $this->makeMirrorArray($row['download_mirror']);
- }
- }
- if ($subAction == "dlm" && !$_POST['submit'])
- {
- require_once(e_PLUGIN.'download/download_shortcodes.php');
- if ($sql->db_Select("upload", "*", "upload_id=".$id))
- {
- $row = $sql->db_Fetch();
- $download_category = $row['upload_category'];
- $download_name = $row['upload_name'].($row['upload_version'] ? " v" . $row['upload_version'] : "");
- $download_url = $row['upload_file'];
- $download_author_email = $row['upload_email'];
- $download_author_website = $row['upload_website'];
- $download_description = $row['upload_description'];
- $download_image = $row['upload_ss'];
- $download_filesize = $row['upload_filesize'];
- $image_array[] = array("path" => "", "fname" => $row['upload_ss']);
- $download_author = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1));
- }
- }
- $text = "
- <div class='admintabs' id='tab-container'>
- <ul class='e-taXXbs' e-hideme' id='core-download-tabs'>
- <li id='tab-general'><a href='#download-create'>".DOWLAN_175."</a></li>
- <li id='tab-external'><a href='#download-edit-external'>".DOWLAN_176."</a></li>
- <li id='tab-mirror'><a href='#download-edit-mirror'>".DOWLAN_128."</a></li>
- </ul>
- <div>
- <form method='post' action='".e_SELF."?".e_QUERY."' id='myform'>
- <fieldset id='download-create'>
- <table style='".ADMIN_WIDTH."' class='adminlist'>
- <tr>
- <td style='width:20%;'>".DOWLAN_13."</td>
- <td style='width:80%'>
- <div>".DOWLAN_131."
- <select name='download_url' class='tbox'>
- <option value=''> </option>
- ";
- $counter = 0;
- while (isset($file_array[$counter]))
- {
- $fpath = str_replace(e_DOWNLOAD,"",$file_array[$counter]['path']).$file_array[$counter]['fname'];
- $selected = '';
- if (stristr($fpath, $download_url) !== FALSE)
- {
- $selected = " selected='selected'";
- $found = 1;
- }
- $text .= "<option value='".$fpath."' $selected>".$fpath."</option>\n";
- $counter++;
- }
- if (preg_match("/http:|https:|ftp:/", $download_url))
- {
- $download_url_external = $download_url;
- $download_url = '';
- }
- $etext = " - (".DOWLAN_68.")";
- if (file_exists(e_UPLOAD.$download_url))
- {
- $etext = "";
- }
- if (!$found && $download_url)
- {
- $text .= "<option value='".$download_url."' selected='selected'>".$download_url.$etext."</option>\n";
- }
- $text .= " </select>
- </div>
- </td>
- </tr>
- </table>
- </fieldset>
- <fieldset id='download-edit-external'>
- <table style='".ADMIN_WIDTH."' class='adminlist'>
- <tr>
- <td style='width:20%;'>".DOWLAN_149."</td>
- <td style='width:80%;'>
- <input class='tbox' type='text' name='download_url_external' size='70' value='{$download_url_external}' maxlength='255'/>
- </td>
- </tr>
- <tr>
- <td>".DOWLAN_66."</td>
- <td>
- <input class='tbox' type='text' name='download_filesize_external' size='8' value='{$download_filesize}' maxlength='10'/>
- </td>
- </tr>
- </table>
- </fieldset>
- <fieldset id='download-edit-mirror'>
- <table style='".ADMIN_WIDTH."' class='adminlist'>
- <tr>
- <td style='width:20%'><span title='".DOWLAN_129."' style='cursor:help'>".DOWLAN_128."</span></td>
- <td style='width:80%'>";
- // See if any mirrors to display
- if (!$sql -> db_Select("download_mirror"))
- { // No mirrors defined here
- $text .= DOWLAN_144."</td></tr>";
- }
- else
- {
- $text .= DOWLAN_132."<div id='mirrorsection'>";
- $mirrorList = $sql -> db_getList(); // Get the list of possible mirrors
- $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); // Count of mirrors actually in use (or count of 1 if none defined yet)
- for($count = 1; $count <= $m_count; $count++)
- {
- $opt = ($count==1) ? "id='mirror'" : "";
- $text .="
- <div {$opt}>
- <select name='download_mirror_name[]' class='tbox'>
- <option value=''> </option>";
- foreach ($mirrorList as $mirror)
- {
- extract($mirror);
- $text .= "<option value='{$mirror_id}'".($mirror_id == $mirrorArray[($count-1)]['id'] ? " selected='selected'" : "").">{$mirror_name}</option>\n";
- }
- $text .= "</select>
- <input class='tbox' type='text' name='download_mirror[]' style='width: 60%;' value=\"".$mirrorArray[($count-1)]['url']."\" maxlength='200'/>
- <input class='tbox' type='text' name='download_mirror_size[]' style='width: 15%;' value=\"".$mirrorArray[($count-1)]['filesize']."\" maxlength='10'/>";
- if (DOWNLOAD_DEBUG)
- {
- if ($id)
- {
- $text .= '('.$mirrorArray[($count-1)]['requests'].')';
- }
- else
- {
- $text .= "<input class='tbox' type='text' name='download_mirror_requests[]' style='width: 10%;' value=\"".$mirrorArray[($count-1)]['requests']."\" maxlength='10'/>";
- }
- }
- $text .= " </div>";
- }
- $text .=" </div>
- <input class='btn button' type='button' name='addoption' value='".DOWLAN_130."' onclick=\"duplicateHTML('mirror','mirrorsection')\"/>
- </td>
- </tr>
- <tr>
- <td style='width:20%' ><span style='cursor:help' title='".DOWLAN_154."'>".DOWLAN_155."</span></td>
- <td style='width:80%'>
- <input type='radio' name='download_mirror_type' value='1'".($download_mirror_type ? " checked='checked'" : "")."/> ".DOWLAN_156."<br/>
- <input type='radio' name='download_mirror_type' value='0'".(!$download_mirror_type ? " checked='checked'" : "")."/> ".DOWLAN_157."
- </td>
- </tr>";
- } // End of mirror-related stuff
- $download_author = $subAction != "edit" && $download_author == "" ? USERNAME : $download_author;//TODO what if editing an no author specified
- $download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email;
- $text .= "
- </table>
- </fieldset>
- <fieldset id='download-edit-therest'>
- <table style='".ADMIN_WIDTH."' class='adminlist'>
- <tr>
- <td style='width:20%'>".DOWLAN_11."</td>
- <td style='width:80%'>";
- $text .= $this->getCategorySelectList($download_category);
- $text .= " </td>
- </tr>
- <tr>
- <td style='width:20%;'>".DOWLAN_12."</td>
- <td style='width:80%'>
- <input class='tbox' type='text' name='download_name' size='60' value=\"".$tp->toForm($download_name)."\" maxlength='200'/>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_15."</td>
- <td style='width:80%'>
- <input class='tbox' type='text' name='download_author' size='60' value='$download_author' maxlength='100'/>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_16."</td>
- <td style='width:80%'>
- <input class='tbox' type='text' name='download_author_email' size='60' value='$download_author_email' maxlength='100'/>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_17."</td>
- <td style='width:80%'>
- <input class='tbox' type='text' name='download_author_website' size='60' value='$download_author_website' maxlength='100'/>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_18."</td>
- <td style='width:80%'>
- ";
- $text .= $frm->bbarea('download_description',$download_description);
- $text .= " </td>
- </tr>
- <tr>
- <td>
- Activation between
- </td>
- <td>
- // TODO
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_19."</td>
- <td style='width:80%'>
- <select name='download_image' class='tbox'>
- <option value=''> </option>";
- foreach($image_array as $img)
- {
- $fpath = str_replace(e_FILE."downloadimages/","",$img['path'].$img['fname']);
- $sel = ($download_image == $fpath) ? " selected='selected'" : "";
- $text .= "<option value='".$fpath."' $sel>".$fpath."</option>\n";
- }
- $text .= " </select>";
- if ($subAction == "dlm" && $download_image)
- {
- $text .= "
- <input type='hidden' name='move_image' value='1'/>\n";
- }
- $text .= " </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_20."</td>
- <td style='width:80%'>
- <select name='download_thumb' class='tbox'>
- <option value=''> </option>";
- foreach($thumb_array as $thm){
- $tpath = str_replace(e_FILE."downloadthumbs/","",$thm['path'].$thm['fname']);
- $sel = ($download_thumb == $tpath) ? " selected='selected'" : "";
- $text .= "<option value='".$tpath."' $sel>".$tpath."</option>\n";
- }
- $text .= " </select>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".LAN_DATESTAMP."</td>
- <td style='width:80%'>";
- if (!$download_datestamp){
- $download_datestamp = time();
- }
- $cal_options['showsTime'] = false;
- $cal_options['showOthers'] = false;
- $cal_options['weekNumbers'] = false;
- $cal_options['ifFormat'] = "%d/%m/%Y %H:%M:%S";
- $cal_options['timeFormat'] = "24";
- $cal_attrib['class'] = "tbox";
- $cal_attrib['size'] = "22";
- $cal_attrib['name'] = "download_datestamp";
- $cal_attrib['value'] = date("d/m/Y H:i:s", $download_datestamp);
- $text .= $cal->make_input_field($cal_options, $cal_attrib);
- $update_checked = ($_POST['update_datestamp']) ? "checked='checked'" : "";
- $text .= " <span><input type='checkbox' value='1' name='update_datestamp' $update_checked/>".DOWLAN_148."</span>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_21."</td>
- <td style='width:80%'>
- <select name='download_active' class='tbox'>";
- foreach($download_status as $key => $val){
- $sel = ($download_active == $key) ? " selected = 'selected' " : "";
- $text .= "<option value='{$key}' {$sel}>{$val}</option>\n";
- }
- $text .= " </select>
- </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_102."</td>
- <td style='width:80%'>";
- if ($download_comment == "0") {
- $text .= LAN_YES.": <input type='radio' name='download_comment' value='1'/>
- ".LAN_NO.": <input type='radio' name='download_comment' value='0' checked='checked'/>";
- } else {
- $text .= LAN_YES.": <input type='radio' name='download_comment' value='1' checked='checked'/>
- ".LAN_NO.": <input type='radio' name='download_comment' value='0'/>";
- }
- $text .= " </td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_145."</td>
- <td style='width:80%'>".r_userclass('download_visible', $download_visible, 'off', 'public, nobody, member, admin, classes, language')."</td>
- </tr>
- <tr>
- <td style='width:20%'>".DOWLAN_106."</td>
- <td style='width:80%'>".r_userclass('download_class', $download_class, 'off', 'public, nobody, member, admin, classes, language')."</td>
- </tr>";
- if ($subAction == "dlm") {
- $text .= "
- <tr>
- <td style='width:30%'>".DOWLAN_153."</td>
- <td style='width:70%'>
- <select name='move_file' class='tbox'>
- <option value=''>".LAN_NO."</option>";
- $dl_dirlist = $fl->get_dirs(e_DOWNLOAD);
- if ($dl_dirlist){
- sort($dl_dirlist);
- $text .= "<option value='".e_DOWNLOAD."'>/</option>\n";
- foreach($dl_dirlist as $dirs)
- {
- $text .= "<option value='". e_DOWNLOAD.$dirs."/'>".$dirs."/</option>\n";
- }
- }
- else
- {
- $text .= "<option value='".e_DOWNLOAD."'>".LAN_YES."</option>\n";
- }
- $text .= " </select>
- </td>
- </tr>
- <tr>
- <td style='width:30%'>".DOWLAN_103."</td>
- <td style='width:70%'>
- <input type='checkbox' name='remove_upload' value='1'/>
- <input type='hidden' name='remove_id' value='$id'/>
- </td>
- </tr>";
- }
- //triggerHook
- $data = array('method'=>'form', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'create_download');
- $hooks = $e107->e_event->triggerHook($data);
- $text .= " <tr style=''>
- <td colspan='2' style='text-align:center'>";
- if ($id && $subAction == "edit") {
- $text .= "<input class='btn button' type='submit' name='submit_download' value='".DOWLAN_24."'/> ";
- } else {
- $text .= "<input class='btn button' type='submit' name='submit_download' value='".DOWLAN_25."'/>";
- }
- $text .= "
- </td>
- </tr>
- </table>
- </fieldset>
- </form>
- </div>
- </div>";
- $ns->tablerender(ADLAN_24, $text);
- }
- */
- // -----------------------------------------------------------------------------
- /*
- function show_message($message) {
- global $ns;
- $ns->tablerender("", "<div style='text-align:center'><b>".$message."</b></div>");
- }
- */
- // -----------------------------------------------------------------------------
- /* // Actually save a new or edited download to the DB
- function submit_download($subAction, $id)
- {
- global $e107, $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event;
- $dlInfo = array();
- $dlMirrors = array();
- if ($subAction == 'edit')
- {
- if ($_POST['download_url_external'] == '')
- {
- $_POST['download_filesize_external'] = FALSE;
- }
- }
- if ($_POST['download_url_external'] && $_POST['download_url'] == '')
- {
- $dlInfo['download_url'] = $tp->toDB($_POST['download_url_external']);
- $filesize = intval($_POST['download_filesize_external']);
- }
- else
- {
- $dlInfo['download_url'] = $tp->toDB($_POST['download_url']);
- if ($_POST['download_filesize_external'])
- {
- $filesize = intval($_POST['download_filesize_external']);
- }
- else
- {
- if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1)
- {
- $filesize = filesize($DOWNLOADS_DIRECTORY.$dlInfo['download_url']);
- }
- else
- {
- $filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$dlInfo['download_url']);
- }
- }
- }
- if (!$filesize)
- {
- if ($sql->db_Select("upload", "upload_filesize", "upload_file='{$dlInfo['download_url']}'"))
- {
- $row = $sql->db_Fetch();
- $filesize = $row['upload_filesize'];
- }
- }
- $dlInfo['download_filesize'] = $filesize;
- // ---- Move Images and Files ------------
- if ($_POST['move_image'])
- {
- if ($_POST['download_thumb'])
- {
- $oldname = e_UPLOAD.$_POST['download_thumb'];
- $newname = e_FILE."downloadthumbs/".$_POST['download_thumb'];
- if (!$this -> move_file($oldname,$newname))
- {
- return;
- }
- }
- if ($_POST['download_image'])
- {
- $oldname = e_UPLOAD.$_POST['download_image'];
- $newname = e_FILE."downloadimages/".$_POST['download_image'];
- if (!$this -> move_file($oldname,$newname))
- {
- return;
- }
- }
- }
- if ($_POST['move_file'] && $_POST['download_url'])
- {
- $oldname = e_UPLOAD.$_POST['download_url'];
- $newname = $_POST['move_file'].$_POST['download_url'];
- if (!$this -> move_file($oldname,$newname))
- {
- return;
- }
- $dlInfo['download_url'] = str_replace(e_DOWNLOAD,"",$newname);
- }
- // ------------------------------------------
- $dlInfo['download_description'] = $tp->toDB($_POST['download_description']);
- $dlInfo['download_name'] = $tp->toDB($_POST['download_name']);
- $dlInfo['download_author'] = $tp->toDB($_POST['download_author']);
- $dlInfo['download_author_email'] = $tp->toDB($_POST['download_author_email']);
- $dlInfo['download_author_website'] = $tp->toDB($_POST['download_author_website']);
- $dlInfo['download_category'] = intval($_POST['download_category']);
- $dlInfo['download_active'] = intval($_POST['download_active']);
- $dlInfo['download_thumb'] = $tp->toDB($_POST['download_thumb']);
- $dlInfo['download_image'] = $tp->toDB($_POST['download_image']);
- $dlInfo['download_comment'] = $tp->toDB($_POST['download_comment']);
- $dlInfo['download_class'] = intval($_POST['download_class']);
- $dlInfo['download_visible'] =intval($_POST['download_visible']);
- if (preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches))
- {
- $dlInfo['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
- }
- else
- {
- $dlInfo['download_datestamp'] = time();
- }
- if ($_POST['update_datestamp'])
- {
- $dlInfo['download_datestamp'] = time();
- }
- $mirrorStr = "";
- $mirrorFlag = FALSE;
- // See if any mirrors defined
- // Need to check all the possible mirror names - might have deleted the first one if we're in edit mode
- foreach ($_POST['download_mirror_name'] as $mn)
- {
- if ($mn)
- {
- $mirrorFlag = TRUE;
- break;
- }
- }
- if ($mirrorFlag)
- {
- $mirrors = count($_POST['download_mirror_name']);
- $mirrorArray = array();
- $newMirrorArray = array();
- if ($id && $sql->db_Select('download','download_mirror', 'download_id = '.$id)) // Get existing download stats
- {
- if ($row = $sql->db_Fetch())
- {
- $mirrorArray = $this->makeMirrorArray($row['download_mirror'], TRUE);
- }
- }
- for($a=0; $a<$mirrors; $a++)
- {
- $mid = trim($_POST['download_mirror_name'][$a]);
- $murl = trim($_POST['download_mirror'][$a]);
- $msize = trim($_POST['download_mirror_size'][$a]);
- if ($mid && $murl)
- {
- $newMirrorArray[$mid] = array('id' => $mid, 'url' => $murl, 'requests' => 0, 'filesize' => $msize);
- if (DOWNLOAD_DEBUG && !$id)
- {
- $newMirrorArray[$mid]['requests'] = intval($_POST['download_mirror_requests'][$a]);
- }
- }
- }
- // Now copy across any existing usage figures
- foreach ($newMirrorArray as $k => $m)
- {
- if (isset($mirrorArray[$k]))
- {
- $newMirrorArray[$k]['requests'] = $mirrorArray[$k]['requests'];
- }
- }
- $mirrorStr = $this->compressMirrorArray($newMirrorArray);
- }
- $dlMirrors['download_mirror']=$mirrorStr;
- $dlMirrors['download_mirror_type']=intval($_POST['download_mirror_type']);
- if ($id)
- { // Its an edit
- // Process triggers before calling admin_update so trigger messages can be shown
- $data = array('method'=>'update', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'update_download');
- $hooks = $e107->e_event->triggerHook($data);
- require_once(e_HANDLER."message_handler.php");
- $emessage = &eMessage::getInstance();
- $emessage->add($hooks, E_MESSAGE_SUCCESS);
- admin_update($sql->db_UpdateArray('download',array_merge($dlInfo,$dlMirrors),'WHERE download_id='.intval($id)), 'update', DOWLAN_2." (<a href='".e_PLUGIN."download/download.php?view.".$id."'>".$_POST['download_name']."</a>)");
- $dlInfo['download_id'] = $id;
- $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors);
- $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings
- unset($dlInfo['download_class']); // Also replicating 0.7
- $e_event->trigger('dlupdate', $dlInfo);
- }
- else
- {
- if ($download_id = $sql->db_Insert('download',array_merge($dlInfo,$dlMirrors)))
- {
- // Process triggers before calling admin_update so trigger messages can be shown
- $data = array('method'=>'create', 'table'=>'download', 'id'=>$download_i…
Large files files are truncated, but you can click here to view the full file