array('controller' =>'CONTROLLER_CLASS'[, 'index' => 'list', 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => 'UI CLASS NAME child of e_admin_ui', 'uipath' => 'UI SCRIPT PATH']); * Note - default mode/action is autodetected in this order: * - $defaultMode/$defaultAction (owned by dispatcher - see below) * - $adminMenu (first key if admin menu array is not empty) * - $modes (first key == mode, corresponding 'index' key == action) * @var array */ protected $modes = array ( 'main' => array ( 'controller' => 'download_main_admin_ui', 'path' => null, 'ui' => 'download_main_admin_form_ui', 'uipath' => null ), 'cat' => array ( 'controller' => 'download_cat_ui', 'path' => null, 'ui' => 'download_cat_form_ui', 'uipath' => null ) ); /* Both are optional protected $defaultMode = null; protected $defaultAction = null; */ /** * Format: 'MODE/ACTION' => array('caption' => 'Menu link title'[, 'url' => '{e_PLUGIN}release/admin_config.php', 'perm' => '0']); * Additionally, any valid e_admin_menu() key-value pair could be added to the above array * @var array */ protected $adminMenu = array( 'main/list' => array('caption'=> 'Manage', 'perm' => 'P'), 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 'cat/list' => array('caption'=> DOWLAN_31, 'perm'=>'P'), 'cat/create' => array('caption'=> "Create Category", 'perm' => 'Q'), 'main/settings' => array('caption'=> 'Settings', 'perm' => 'P'), 'main/maint' => array('caption'=> DOWLAN_165, 'perm' => 'P'), 'main/limits' => array('caption'=> DOWLAN_112, 'perm' => 'P'), 'main/mirror' => array('caption'=> DOWLAN_128, 'perm' => 'P') ); /* $var['main']['text'] = DOWLAN_29; $var['main']['link'] = e_SELF; $var['create']['text'] = DOWLAN_30; $var['create']['link'] = e_SELF."?create"; $var['cat']['text'] = DOWLAN_31; $var['cat']['link'] = e_SELF."?cat"; $var['cat']['perm'] = "Q"; $var['opt']['text'] = LAN_OPTIONS; $var['opt']['link'] = e_SELF."?opt"; $var['maint']['text'] = DOWLAN_165; $var['maint']['link'] = e_SELF."?maint"; $var['limits']['text'] = DOWLAN_112; $var['limits']['link'] = e_SELF."?limits"; $var['mirror']['text'] = DOWLAN_128; $var['mirror']['link'] = e_SELF."?mirror"; e_admin_menu(DOWLAN_32, $action, $var); unset($var); $var['ulist']['text'] = DOWLAN_22; $var['ulist']['link'] = e_SELF."?ulist";; $var['filetypes']['text'] = DOWLAN_23; $var['filetypes']['link'] = e_SELF."?filetypes"; $var['uopt']['text'] = LAN_OPTIONS; $var['uopt']['link'] = e_SELF."?uopt"; */ /** * Optional, mode/action aliases, related with 'selected' menu CSS class * Format: 'MODE/ACTION' => 'MODE ALIAS/ACTION ALIAS'; * This will mark active main/list menu item, when current page is main/edit * @var array */ protected $adminMenuAliases = array( 'main/edit' => 'main/list', 'cat/edit' => 'cat/list' ); /** * Navigation menu title * @var string */ protected $menuTitle = 'Downloads Menu'; } class download_cat_ui extends e_admin_ui { protected $pluginTitle = 'Download Categories'; protected $pluginName = 'download'; protected $table = "download_category"; protected $pid = "download_category_id"; protected $perPage = 0; //no limit protected $listOrder = 'download_category_order'; // protected $defaultOrderField = 'download_category_parent,download_category_order'; // protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit. // protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}"; protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'icon', 'width' => '5%', 'thclass' => 'center','class'=>'center' ), 'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE), 'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left'), 'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'download_category_parent' => array('title'=> 'Parent', 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center') ); function getDownloadCategoryTree($id = false, $default = 'n/a') { // TODO get faq category tree $sql = e107::getDb(); $sql -> db_Select_gen('SELECT * FROM #download_category ORDER BY download_category_order'); $cats = array(); $cats[0] = $default; while($row = $sql->db_Fetch()) { $cats[$row['download_category_id']] = $row['download_category_name']; } if($id) { return $cats[$id]; } return $cats; } } class download_cat_form_ui extends e_admin_form_ui { public function download_category_parent($curVal,$mode) { // TODO - catlist combo without current cat ID in write mode, parents only for batch/filter // Get UI instance $controller = $this->getController(); switch($mode) { case 'read': return e107::getParser()->toHTML($controller->getDownloadCategoryTree($curVal), false, 'TITLE'); break; case 'write': return $this->selectbox('download_category_parent', $controller->getDownloadCategoryTree(), $curVal); break; case 'filter': case 'batch': return $controller->getDownloadCategoryTree(); break; } } } class download_main_admin_ui extends e_admin_ui { // required protected $pluginTitle = "Downloads"; protected $pluginName = 'download'; protected $table = "download"; // DB Table, table alias is supported. Example: 'r.release' protected $listQry = "SELECT m.*,u.user_id,u.user_name FROM #download AS m LEFT JOIN #user AS u ON m.download_author = u.user_id "; // without any Order or Limit. //required - default column user prefs protected $fieldpref = array('checkboxes', 'download_id', 'download_category', 'download_name', 'fb_template', 'fb_class', 'fb_order', 'options'); // // optional - required only in case of e.g. tables JOIN. This also could be done with custom model (set it in init()) //protected $editQry = "SELECT * FROM #release WHERE release_id = {ID}"; // required - if no custom model is set in init() (primary id) protected $pid = "download_id"; // optional protected $perPage = 10; // default - true - TODO - move to displaySettings protected $batchDelete = true; protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect'), 'download_id' => array('title'=> ID, 'type' => 'number', 'data' => 'int', 'width'=>'5%', 'thclass' => '', 'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable 'download_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), 'download_url' => array('title'=> DOWLAN_13, 'type' => 'url', 'data' => 'str', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE), 'download_author' => array('title'=> LAN_AUTHOR, 'type' => 'user', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_author_email' => array('title'=> DOWLAN_16, 'type' => 'email', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_author_website' => array('title'=> DOWLAN_17, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'download_filesize' => array('title'=> DOWLAN_66, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'right', 'class' => 'right'), 'download_requested' => array('title'=> DOWLAN_29, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'right', 'class' => 'right'), 'download_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'batch' => TRUE, 'filter'=>TRUE), 'download_active' => array('title'=> DOWLAN_21, 'type' => 'method', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), 'download_datestamp' => array('title'=> LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'readParms' => 'long', 'writeParms' => ''), 'download_thumb' => array('title'=> DOWLAN_20, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE ), 'download_image' => array('title'=> DOWLAN_19, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'batch' => FALSE, 'filter'=>FALSE), 'download_comment' => array('title'=> DOWLAN_102, 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), 'download_class' => array('title'=> DOWLAN_113, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int','batch' => TRUE, 'filter'=>TRUE), 'download_visible' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE), 'download_mirror' => array('title'=> DOWLAN_128, 'type' => 'text', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), 'download_mirror_type' => array('title'=> DOWLAN_195, 'type' => 'method', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), // 'download_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'left' ), 'issue' => array('title'=> 'Issue', 'type' => 'method', 'data' => null, 'nolist'=>TRUE, 'noedit'=>TRUE, 'filter'=>TRUE), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE) ); protected $action = array(); protected $subAction = array(); protected $id = ""; /* $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) ); */ // FORMAT field_name=>type - optional if fields 'data' attribute is set or if custom model is set in init() /*protected $dataFields = array();*/ // optional, could be also set directly from $fields array with attributes 'validate' => true|'rule_name', 'rule' => 'condition_name', 'error' => 'Validation Error message' /*protected $validationRules = array( 'release_url' => array('required', '', 'Release URL', 'Help text', 'not valid error message') );*/ // optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName); protected $prefs = array( 'pref_type' => array('title'=> 'type', 'type'=>'text', 'data' => 'string', 'validate' => true), 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean', 'data' => 'integer'), 'pref_name' => array('title'=> 'name', 'type' => 'text', 'data' => 'string', 'validate' => 'regex', 'rule' => '#^[\w]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore') ); public function observe() { if (isset($_POST['submit_download'])) // Create or Update a Download. { $this->submit_download(); } if (isset($_POST['updatedownlaodoptions'])) // Save Download Options. { $this->saveSettings(); } if (isset($_POST['submit_mirror'])) { $this->submit_mirror(); } if (isset($_POST)) { e107::getCache()->clear("download_cat"); } } // optional public function init() { $this->action = $_GET['mode']; $this->subAction = $_GET['action']; $this->id = $_GET['id']; $this->observe(); $categories = array(); if(e107::getDb()->db_Select('download_category')) { //$categories[0] = LAN_SELECT; while ($row = e107::getDb()->db_Fetch()) { $id = $row['download_category_id']; $categories[$id] = $row['download_category_name']; } } $this->fields['download_category']['writeParms'] = $categories; // DEPRECATED //$this->fields['fb_rendertype']['writeParms'] = array(FBLAN_23,FBLAN_24); //$this->fields['fb_mode']['writeParms'] = array(FBLAN_13,FBLAN_14); $this->fields['download_category']['readParms'] = $categories; // Custom filter queries if($_GET['filter_options']) { list($filter,$mode) = explode("__",$_GET['filter_options']); if($mode == 'missing') { $this->filterQry = $this->missingFiles(); } if($mode == 'nocategory') { $this->filterQry = "SELECT * FROM `#download` WHERE download_category=0"; } if($mode == 'duplicates') { $this->filterQry = "SELECT GROUP_CONCAT(d.download_id SEPARATOR ',') as gc, d.download_id, d.download_name, d.download_url, dc.download_category_name FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id=d.download_category GROUP BY d.download_url HAVING COUNT(d.download_id) > 1"; } if($mode == "filesize") { $this->filterQry = $this->missingFiles('filesize'); } } } /* * Return a query for Missing Files and Filesize mismatch */ public function missingFiles($mode='missing') { $sql = e107::getDb(); $count = array(); if ($sql->db_Select_gen("SELECT * FROM `#download` ORDER BY download_id")) { while($row = $sql->db_Fetch()) { if (!is_readable(e_DOWNLOAD.$row['download_url'])) { $count[] = $row['download_id']; } elseif($mode == 'filesize') { $filesize = filesize(e_DOWNLOAD.$row['download_url']); if ($filesize <> $row['download_filesize']) { $count[] = $row['download_id']; } } } } if($count > 0) { return "SELECT * FROM `#download` WHERE download_id IN (".implode(",",$count).")"; } } function orphanFiles() //TODO { $files = e107::getFile()->get_files(e_DOWNLOAD); $foundSome = false; foreach($files as $file) { if (0 == $sql->db_Count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { if (!$foundSome) { // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); $text .= '