1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2008-2013 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * File Upload facility - administration 10 * 11 */ 12 13require_once('../class2.php'); 14if (!getperms('V')) 15{ 16 e107::redirect('admin'); 17 exit; 18} 19 20e107::lan('core','upload','admin'); 21 22$e_sub_cat = 'upload'; 23 24 25// Generated e107 Plugin Admin Area 26 27class upload_admin extends e_admin_dispatcher 28{ 29 30 protected $modes = array( 31 32 'main' => array( 33 'controller' => 'upload_ui', 34 'path' => null, 35 'ui' => 'upload_form_ui', 36 'uipath' => null 37 ), 38 39 ); 40 41 42 protected $adminMenu = array( 43 44 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'V'), 45 // 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'V'), 46 // 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'V'), 47 48 /* 49 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), 50 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P') 51 */ 52 53 ); 54 55 protected $adminMenuAliases = array( 56 'main/edit' => 'main/list' 57 ); 58 59 protected $menuTitle = LAN_UPLOAD; 60 61 protected $adminMenuIcon = 'e-uploads-24'; 62} 63 64 65 66 67 68class upload_ui extends e_admin_ui 69{ 70 71 protected $pluginTitle = LAN_UPLOAD; 72 protected $pluginName = 'core'; 73 protected $table = 'upload'; 74 protected $pid = 'upload_id'; 75 protected $perPage = 10; 76 77 protected $fields = array ( 78 'checkboxes' => array ( 'title' => '', 'type' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => true, 'class' => 'center', 'toggle' => 'e-multiselect', ), 79 'upload_id' => array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 80 'upload_datestamp' => array ( 'title' => LAN_DATESTAMP, 'type' => 'datestamp', 'data' => 'int', 'width' => '15%', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 81 'upload_name' => array ( 'title' => LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => '15%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', 'validate' => true, 'inline' => true), 82 'upload_email' => array ( 'title' => LAN_EMAIL, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 83 'upload_website' => array ( 'title' => LAN_URL, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 84 'upload_version' => array ( 'title' => LAN_VERSION, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 85 'upload_file' => array ( 'title' => LAN_FILE, 'type' => 'text', 'data' => 'str', 'width' => '15%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', 'validate' => true ), 86 'upload_ss' => array ( 'title' => 'Ss', 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 87 'upload_description' => array ( 'title' => LAN_DESCRIPTION, 'type' => 'textarea', 'data' => 'str', 'width' => '30%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 88 'upload_poster' => array ( 'title' => UPLLAN_5, 'type' => 'user', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 89 90 'upload_demo' => array ( 'title' => UPLLAN_14, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 91 'upload_filesize' => array ( 'title' => LAN_SIZE, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 92 'upload_active' => array ( 'title' => UPLLAN_69, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => array('singleOption' => true), 'class' => 'center', 'thclass' => 'center', 'batch' => true, 'filter'=>true), 93 'upload_category' => array ( 'title' => LAN_CATEGORY, 'type' => 'method', 'data' => 'int', 'width' => 'auto', 'batch' => true, 'filter' => true, 'help' => '', 'readParms' => array(), 'writeParms' => array(), 'class' => 'left', 'thclass' => 'left', 'validate' => true ), 94 'upload_owner' => array ( 'title' => LAN_OWNER, 'type' => 'text', 'readonly'=>true, 'data' => 'str', 'width' => '10%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 95 96 'options' => array ( 'title' => LAN_OPTIONS, 'type' => '', 'data' => '', 'width' => '140px', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ), 97 ); 98 99 protected $fieldpref = array('checkboxes', 'upload_datestamp', 'upload_name', 'upload_description', 'upload_file', 'upload_filesize', 'upload_poster','upload_name', 'upload_category', 'upload_owner', 'upload_active', 'options'); 100/* 101 protected $prefs = array( 102 'upload_categories' => array('title'=> 'Display Contact info on Contact form', 'type'=>'checkboxes', 'data'=>'int'), 103 104 // 'classic_look' => array('title'=> 'Use Classic Layout', 'type'=>'boolean') 105 ); 106*/ 107 108 109 110 public $categories = array(); 111 112 // optional 113 public function init() 114 { 115 116 $this->categories = e107::getAddonConfig('e_upload','','category'); 117 118 // $this->prefs['upload_categories']['writeParms']['optArray'] = array(1,2,3,4); 119 120 121 /* $qry = " 122 SELECT dc.download_category_name, dc.download_category_id 123 FROM #download_category AS dc 124 WHERE dc.download_category_parent = 0 125 ORDER by dc.download_category_order ASC"; 126 $cats = e107::getDb('dc')->retrieve($qry, null, null, true, 'download_category_id'); 127 128 $parentIndex = array_keys($cats); 129 $subIndex = array(); 130 131 $qry = " 132 SELECT dc.download_category_name, dc.download_category_parent, dc.download_category_id 133 FROM #download_category AS dc 134 WHERE dc.download_category_parent != 0 135 ORDER by dc.download_category_order ASC"; 136 if(e107::getDb('dc')->gen($qry)) 137 { 138 while($row = e107::getDb('dc')->fetch()) 139 { 140 $subIndex[$row['download_category_parent']][] = $row['download_category_id']; 141 $cats[$row['download_category_id']] = $row; 142 } 143 } 144 145 foreach ($parentIndex as $id) 146 { 147 $parent = $cats[$id]; 148 $label = e107::getParser()->toHTML($parent['download_category_name'], false, 'TITLE'); 149 $this->addSubcategories($id, $cats, $subIndex, $label); 150 }*/ 151 } 152 153 154 private function addSubcategories($parent_id, &$cats, $subIndex, $label) 155 { 156 if(isset($subIndex[$parent_id])) 157 { 158 foreach ($subIndex[$parent_id] as $sub_id) 159 { 160 $cat = $cats[$sub_id]; 161 $_label = e107::getParser()->toHTML($cat['download_category_name'], false, 'TITLE'); 162 if($cat['download_category_parent'] && isset($subIndex[$sub_id])) 163 { 164 $this->addSubcategories($sub_id, $cats, $subIndex, $label.' / '.$_label); 165 } 166 else 167 { 168 if($this->getAction() == 'list') 169 { 170 $this->fields['upload_category']['writeParms'][$sub_id] = $label.' / '.$_label; 171 } 172 else 173 { 174 $this->fields['upload_category']['writeParms'][$label][$sub_id] = $_label; 175 } 176 } 177 } 178 } 179 } 180 181 protected function handleListUploadActiveBatch($selected, $value = null) 182 { 183 $ids = array_map('intval', array_values($selected)); 184 foreach ($ids as $id) 185 { 186 $model = $this->getTreeModel()->getNode($id); 187 if($model) 188 { 189 $data = $model->toArray(); 190 $data['upload_active'] = 1; 191 $this->afterUpdate($data, $data, $id); 192 } 193 } 194 } 195 196 /** 197 * @inheritdoc 198 */ 199 public function beforeUpdate($new_data, $old_data, $id) 200 { 201 202 if($new_data['upload_active'] && !e107::isInstalled('download')) 203 { 204 $this->getModel()->addValidationError(UPLLAN_62); 205 $new_data['upload_active'] = 0; 206 return $new_data; 207 } 208 209 // Make sure the upload_category contains only integers 210 // Make sure the owner correspondents to the category id 211 list($catOwner, $catID) = explode("__", $new_data['upload_category'], 2); 212 $new_data['upload_category'] = intval($catID); 213 $new_data['upload_owner'] = $catOwner; 214 215 return $new_data; 216 } 217 218 /** 219 * @inheritdoc 220 */ 221 public function afterUpdate($new_data, $old_data, $id) 222 { 223 224 $did = $this->move2download($new_data); 225 $isSession = vartrue($_POST['__after_submit_action']) && !isset($_POST['e__execute_batch']) != 'edit' ? true : false; 226 if($did) 227 { 228 $sql = e107::getDb('activate'); 229 if(!$sql->update('upload', 'upload_active = 1 WHERE upload_id='.$id)) 230 { 231 e107::getMessage() 232 ->addError(UPLLAN_68.' #'.$sql->getLastErrorNumber().' '.$sql->getLastErrorText(), 'default', $isSession) 233 ->addDebug($sql->getLastQuery(), 'default', $isSession); 234 } 235 else 236 { 237 $owner = varset($new_data['upload_owner'],'download'); 238 $obj = e107::getAddon($owner,'e_upload'); 239 $config = $obj->config(); 240 $url = str_replace('{ID}',$did, $config['url']); 241 242 $link = '<br><a href="'.$url.'">'.UPLLAN_64.'</a>'; //FIXME Needs generic LAN for all areas, not just downloads. 243 $message = str_replace('[x]', $link, UPLLAN_63); 244 245 e107::getMessage()->addSuccess($message, 'default', $isSession); 246 } 247 248 } 249 } 250 251 /** 252 * @inheritdoc 253 */ 254 public function afterDelete($deleted_data, $id, $deleted_check) 255 { 256 if($deleted_check) 257 { 258 $uploadFile = e_UPLOAD.$deleted_data['upload_file']; 259 $uploadImage = e_UPLOAD.$deleted_data['upload_ss']; 260 @unlink($uploadFile); 261 @unlink($uploadImage); 262 } 263 } 264 265 protected function move2download($upload) 266 { 267 268 if(!$upload['upload_active']) 269 { 270 return 0; 271 } 272 273 // Make sure the owner is not empty 274 $owner = vartrue($upload['upload_owner'], 'download'); 275 276 $uploadObj = e107::getAddon($owner,'e_upload'); 277 278 $config = $uploadObj->config(); // import configuration from e_upload 279 280 $mediaFile = varset($config['media']['file'],'_common_file'); 281 $mediaImage = varset($config['media']['preview'], '_common_image'); 282 283 284 $media = e107::getMedia(); 285 $uploadPath = e_UPLOAD; 286 if(!file_exists($uploadPath.$upload['upload_file'])) 287 { 288 $this->getModel()->addValidationError(LAN_FILE_NOT_FOUND); 289 return false; 290 } 291 292 $downloadPath = $media->importFile($upload['upload_file'], $mediaFile, $uploadPath.$upload['upload_file'], array('media_caption' => $upload['upload_name'])); 293 if(false === $downloadPath) 294 { 295 $this->getModel()->addValidationError(UPLLAN_66); 296 return false; 297 } 298 299 $imagePath = null; 300 if($upload['upload_ss'] && file_exists($uploadPath.$upload['upload_ss'])) 301 { 302 $imagePath = $media->importFile($upload['upload_ss'], $mediaImage, $uploadPath.$upload['upload_ss'], array('media_caption' => $upload['upload_name'].' '.LAN_PREVIEW)); 303 } 304 305 $author = $upload['upload_poster'] ? e107::getSystemUser($upload['upload_poster'])->getRealName() : LAN_ANONYMOUS; 306 307 $upload['upload_ss'] = $imagePath; 308 $upload['upload_file'] = $downloadPath; 309 $upload['upload_poster'] = $author; 310 311 $dl = $uploadObj->insert($upload); 312 313 $sql = e107::getDb('activate'); 314 315 if(!empty($dl) && !empty($config['table'])) 316 { 317 $id = $sql->insert($config['table'], $dl); 318 319 if(!$id) 320 { 321 $this->getModel()->addValidationError(UPLLAN_68.' #'.$sql->getLastErrorNumber().' '.$sql->getLastErrorText()); 322 e107::getMessage()->addDebug($sql->getLastQuery()); 323 return null; 324 } 325 326 return $id; 327 } 328 else 329 { 330 e107::getMessage()->addDebug('table: '.$config['table']); 331 e107::getMessage()->addDebug('data: '.print_a($dl,true)); 332 333 return false; 334 } 335 336 337 } 338 339} 340 341 342 343class upload_form_ui extends e_admin_form_ui 344{ 345 private function findKey($owner, $array,$value) 346 { 347 $searchKey = $owner."__".$value; 348 349 $ret = null; 350 351 foreach($array as $k=>$v) 352 { 353 if(is_array($v)) 354 { 355 $ret = $this->findKey($owner,$v,$value); 356 } 357 elseif($k == $searchKey) 358 { 359 $ret = $v; 360 } 361 362 } 363 364 return $ret; 365 // return print_a($array,true); 366 } 367 368 369 public function upload_category($value, $type, $options = array()) 370 { 371 372 $opts = $this->getController()->categories; 373 374 switch($type) 375 { 376 case 'read': 377 $owner = $this->getController()->getListModel()->get('upload_owner'); 378 return $this->findKey($owner, $opts[$owner], $value); 379 break; 380 381 case 'write': 382 $owner = $this->getController()->getModel()->get('upload_owner'); 383 //return $value."-- ".$owner; // $this->radio_switch('upload_active', $value, LAN_ACCEPT, LAN_PENDING, $options); 384 // make category editable instead of just displaying data 385 return e107::getForm()->select('upload_category', $opts, $value); 386 break; 387 388 case 'batch': 389 390 return array(); 391 392 $pref = e107::getAddonConfig('e_upload'); 393 394 $tp = e107::getParser(); 395 396 $lan = UPLLAN_70; 397 $text = ''; 398 foreach($pref as $k=>$v) 399 { 400 $def = $v['name']; 401 $diz = $tp->lanVars($lan,$def); 402 $text .= $this->option($diz, 'send_to_'.$k, false, array('other' => 'style="padding-left: 15px"')); 403 } 404 405 return $text; 406 // $text = $this->option(LAN_ACCEPT, 'upload_active', false, array('other' => 'style="padding-left: 15px"')); 407 408 409 // return $text; // $this->option('Accept', 'upload_active', false, array('other' => 'style="padding-left: 15px"')); 410 break; 411 } 412 } 413 414 415 416 417 418 public function upload_active($value, $type, $options = array()) 419 { 420 switch($type) 421 { 422 case 'write': 423 return $this->radio_switch('upload_active', $value, LAN_ACCEPT, LAN_PENDING, $options); 424 break; 425 426 case 'read': 427 return $value ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON; 428 break; 429 430 case 'batch': 431 432 //TODO move all 'downloads' specific code into e_upload.php . 433 /* 434 $pref = e107::pref('core', 'e_upload_list'); 435 foreach($pref as $k=>$v) 436 { 437 $def = 'LAN_PLUGIN_'.strtoupper($v).'_NAME'; 438 $text = $this->option('Send to '.defset($def,$v), 'send_to_'.$k, false, array('other' => 'style="padding-left: 15px"')); 439 } 440 */ 441 442 $text = $this->option(LAN_ACCEPT, 'upload_active', false, array('other' => 'style="padding-left: 15px"')); 443 444 445 return $text; // $this->option('Accept', 'upload_active', false, array('other' => 'style="padding-left: 15px"')); 446 break; 447 448 case 'filter': 449 return array(0=>LAN_NO, 1=>LAN_YES); 450 break; 451 } 452 } 453 454 public function upload_filesize($value, $type, $options = array()) 455 { 456 switch($type) 457 { 458 459 460 case 'read': 461 case 'write': 462 return e107::getFile()->file_size_encode($value); 463 break; 464 465 case 'batch': 466 467 break; 468 } 469 } 470} 471 472 473new upload_admin(); 474 475require_once(e_ADMIN."auth.php"); 476e107::getAdminUI()->runPage(); 477 478require_once(e_ADMIN."footer.php"); 479exit; 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514$action = 'list'; // Default action 515if (e_QUERY) 516{ 517 $tmp = explode('.', e_QUERY); 518 $action = $tmp[0]; 519 $id = varset($tmp[1],0); 520} 521 522 523 524if ($action == "dis" && isset($_POST['updelete']['upload_'.$id]) ) 525{ 526 $res = $sql -> db_Select("upload", "*", "upload_id='".intval($id)."'"); 527 $row = $sql -> db_Fetch(); 528 if (preg_match("#Binary (.*?)/#", $row['upload_file'], $match)) 529 { 530 $sql -> db_Delete("rbinary", "binary_id='".$tp -> toDB($match[1])."'"); 531 } 532 else if ($row['upload_file'] && file_exists(e_UPLOAD.$row['upload_file'])) 533 { 534 unlink(e_UPLOAD.$row['upload_file']); 535 } 536 if (preg_match("#Binary (.*?)/#", $row['upload_ss'], $match)) 537 { 538 $sql -> db_Delete("rbinary", "binary_id='".$tp -> toDB($match[1])."'"); 539 } 540 else if ($row['upload_ss'] && file_exists(e_FILE."public/".$row['upload_ss'])) 541 { 542 unlink(e_UPLOAD.$row['upload_ss']); 543 } 544 $message = ($sql->db_Delete("upload", "upload_id='".intval($id)."'")) ? UPLLAN_1 : LAN_DELETED_FAILED; 545 e107::getLog()->add('UPLOAD_01',$row['upload_file'],E_LOG_INFORMATIVE,''); 546} 547 548if ($action == "dlm") 549{ 550 header("location: ".e_ADMIN."download.php?dlm.".$id); 551 exit; 552} 553 554if ($action == "news") 555{ 556 header("location: ".e_ADMIN."newspost.php?create.upload.".$id); 557 exit; 558} 559 560 561if ($action == "dl") 562{ 563 $id = str_replace("%20", " ", $id); 564 565// if (preg_match("/Binary\s(.*?)\/.*/", $id, $result)) 566// { 567// $bid = $result[1]; 568// $result = @mysql_query("SELECT * FROM ".MPREFIX."rbinary WHERE binary_id='$bid' "); 569// $binary_data = @mysql_result($result, 0, "binary_data"); 570// $binary_filetype = @mysql_result($result, 0, "binary_filetype"); 571// $binary_name = @mysql_result($result, 0, "binary_name"); 572// header("Content-type: ".$binary_filetype); 573// header("Content-length: ".$download_filesize); 574// header("Content-Disposition: attachment; filename=".$binary_name); 575// header("Content-Description: PHP Generated Data"); 576// echo $binary_data; 577// exit; 578// } 579// else 580// { 581// header("location:".e_UPLOAD.str_replace("dl.", "", e_QUERY)); 582// exit; 583// } 584} 585 586require_once(e_HANDLER.'upload_handler.php'); 587require_once("auth.php"); 588require_once(e_HANDLER.'userclass_class.php'); 589$gen = new convert; 590require_once(e_HANDLER.'form_handler.php'); 591$rs = new form; 592 593 594// Need the userclass object for class selectors 595if (!is_object($e_userclass)) { $e_userclass = new user_class; } 596 597 598if (isset($_POST['optionsubmit'])) 599{ 600 $temp = array(); 601 $temp['upload_storagetype'] = $_POST['upload_storagetype']; 602 $temp['upload_maxfilesize'] = $_POST['upload_maxfilesize']; 603 $temp['upload_class'] = $_POST['upload_class']; 604 $temp['upload_enabled'] = (FILE_UPLOADS ? $_POST['upload_enabled'] : 0); 605 if ($temp['upload_enabled'] && !$sql->db_Select("links", "*", "link_url='upload.php' ")) 606 { 607 $sql->db_Insert("links", "0, '".LAN_UPLOAD."', 'upload.php', '', '', 1,0,0,0,0"); 608 } 609 610 if (!$temp['upload_enabled'] && $sql->db_Select("links", "*", "link_url='upload.php' ")) 611 { 612 $sql->db_Delete("links", "link_url='upload.php' "); 613 } 614 615 if ($admin_log->logArrayDiffs($temp, $pref, 'UPLOAD_02')) 616 { 617 save_prefs(); // Only save if changes 618 $message = UPLLAN_2; 619 } 620 else 621 { 622 $message = UPLLAN_4; 623 } 624} 625 626if (isset($message)) 627{ 628 require_once(e_HANDLER.'message_handler.php'); 629 message_handler("ADMIN_MESSAGE", $message); 630} 631 632if (!FILE_UPLOADS) 633{ 634 message_handler("ADMIN_MESSAGE", UPLLAN_41); 635} 636 637 638switch ($action) 639{ 640 case 'filetypes' : 641 if(!getperms('0')) exit; 642 643 $definition_source = LAN_DEFAULT; 644 $source_file = ''; 645 $edit_upload_list = varset($_POST['upload_do_edit'],FALSE); 646 647 if (isset($_POST['generate_filetypes_xml'])) 648 { // Write back edited data to filetypes_.xml 649 $file_text = "<e107Filetypes>\n"; 650 foreach ($_POST['file_class_select'] as $k => $c) 651 { 652 if (!isset($_POST['file_line_delete_'.$c]) && vartrue($_POST['file_type_list'][$k])) 653 { 654// echo "Key: {$k} Class: {$c} Delete: {$_POST['file_line_delete'][$k]} List: {$_POST['file_type_list'][$k]} Size: {$_POST['file_maxupload'][$k]}<br />"; 655 $file_text .= " <class name='{$c}' type='{$_POST['file_type_list'][$k]}' maxupload='".vartrue($_POST['file_maxupload'][$k],ini_get('upload_max_filesize'))."' />\n"; 656 } 657 } 658 $file_text .= "</e107Filetypes>\n"; 659 if ((($handle = fopen(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES,'wt')) == FALSE) 660 || (fwrite($handle,$file_text) == FALSE) 661 || (fclose($handle) == FALSE)) 662 { 663 $text = UPLLAN_61.e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES; 664 } 665 else 666 { 667 $text = ''; 668 $text .= '<br />'.UPLLAN_59.e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES.'. '.UPLLAN_60.e_ADMIN.e_READ_FILETYPES.'<br />'; 669 } 670 $ns->tablerender(LAN_FILETYPES, $text); 671 } 672 673 674 $current_perms = array(); 675 if (($edit_upload_list && is_readable(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES)) || (!$edit_upload_list && is_readable(e_ADMIN.e_READ_FILETYPES))) 676 { 677 $xml = e107::getXml(); 678 $source_file = $edit_upload_list ? e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES : e_ADMIN.e_READ_FILETYPES; 679 $temp_vars = $xml->loadXMLfile($source_file, true, false); 680 if ($temp_vars === FALSE) 681 { 682 echo "Error parsing XML file!"; 683 } 684 else 685 { 686 foreach ($temp_vars['class'] as $v1) 687 { 688 $v = $v1['@attributes']; 689 $current_perms[$v['name']] = array('type' => $v['type'],'maxupload' => $v['maxupload']); 690 } 691 } 692 } 693 elseif (is_readable(e_ADMIN.'filetypes.php')) 694 { 695 $source_file = 'filetypes.php'; 696 $current_perms[e_UC_MEMBER] = array('type' => implode(',',array_keys(get_allowed_filetypes('filetypes.php', ''))),'maxupload' => '2M'); 697 if (is_readable(e_ADMIN.'admin_filetypes.php')) 698 { 699 $current_perms[e_UC_ADMIN] = array('type' => implode(',',array_keys(get_allowed_filetypes('admin_filetypes.php', ''))),'maxupload' => '2M'); 700 $source_file .= ' + admin_filetypes.php'; 701 } 702 } 703 else 704 { // Set a default 705 $current_perms[e_UC_MEMBER] = array('type' => 'zip,tar,gz,jpg,png','maxupload' => '2M'); 706 } 707 $text = "<div style='text-align:center'> 708 <form method='post' action='".e_SELF."?filetypes'> 709 <table style='".ADMIN_WIDTH."' class='fborder'> 710 <colgroup> 711 <col style='width:30%' /> 712 <col style='width:40%' /> 713 <col style='width:25%' /> 714 <col style='width:5%' /> 715 </colgroup> 716 <tr> 717 <td class='forumheader3' colspan='4'><input type='hidden' name='upload_do_edit' value='1'>". 718 str_replace(array('[x]', '[y]'),array(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES,e_ADMIN.e_READ_FILETYPES),UPLLAN_52)."</td> 719 </tr> 720 <tr> 721 <td class='forumheader3' colspan='4'>".UPLLAN_57.$source_file."</td> 722 </tr> 723 <tr> 724 <td class='fcaption'>".LAN_USERCLASS."</td> 725 <td class='fcaption'>".UPLLAN_54."</td> 726 <td class='fcaption' style='text-align:center'>".UPLLAN_55."</td> 727 <td class='fcaption' style='text-align:center'>".LAN_DELETE."</td> 728 </tr>"; 729 foreach ($current_perms as $uclass => $uinfo) 730 { 731 $text .= " 732 <tr> 733 <td class='forumheader3'><select name='file_class_select[]' class='tbox'> 734 ".$e_userclass->vetted_tree('file_class_select',array($e_userclass,'select'), $uclass,'member,main,classes,admin, no-excludes')." 735 </select></td> 736 <td class='forumheader3'><input type='text' name='file_type_list[]' value='{$uinfo['type']}' class='tbox' size='40' /></td> 737 <td class='forumheader3' style='text-align:center'><input type='text' name='file_maxupload[]' value='{$uinfo['maxupload']}' class='tbox' size='10' /></td> 738 <td class='forumheader3'><input type='checkbox' value='1' name='file_line_delete_{$uclass}' /></td> 739 </tr>"; 740 } 741 // Now put up a box to add a new setting 742 $text .= " 743 <tr> 744 <td class='forumheader3'><select name='file_class_select[]' class='tbox'> 745 ".$e_userclass->vetted_tree('file_class_select',array($e_userclass,'select'), '','member,main,classes,admin,blank, no-excludes')." 746 </select></td> 747 <td class='forumheader3'><input type='text' name='file_type_list[]' value='' class='tbox' size='40' /></td> 748 <td class='forumheader3' style='text-align:center'><input type='text' name='file_maxupload[]' value='".ini_get('upload_max_filesize')."' class='tbox' size='10' /></td> 749 <td class='forumheader3'> </td> 750 </tr>"; 751 $text .= " 752 <tr> 753 <td class='forumheader3' style='text-align:center' colspan='4'> 754 <input class='btn btn-default btn-secondary button' type='submit' name='generate_filetypes_xml' value='".UPLLAN_56."' /> 755 </td> 756 </tr> 757 </table></form> 758 </div>"; 759 760 $ns->tablerender(LAN_FILETYPES, $text); 761 break; 762 763 case 'options' : 764 if(!getperms('0')) exit; 765 $text = "<div style='text-align:center'> 766 <form method='post' action='".e_SELF."?options'> 767 <table style='".ADMIN_WIDTH."' class='fborder'> 768 <tr> 769 <td style='width:50%' class='forumheader3'>".UPLLAN_25."<br /> 770 <span class='smalltext'>".UPLLAN_26."</span></td> 771 <td style='width:50%' class='forumheader3'>". ($pref['upload_enabled'] == 1 ? $rs->form_radio("upload_enabled", 1, 1)." ".LAN_YES.$rs->form_radio("upload_enabled", 0)." ".LAN_NO : $rs->form_radio("upload_enabled", 1)." ".LAN_YES.$rs->form_radio("upload_enabled", 0, 1)." ".LAN_NO)." 772 </td> 773 </tr> 774 775 <tr> 776 <td style='width:70%' class='forumheader3'>".UPLLAN_33."<br /> 777 <span class='smalltext'>".UPLLAN_34." (upload_max_filesize = ".ini_get('upload_max_filesize').", post_max_size = ".ini_get('post_max_size')." )</span></td> 778 <td style='width:30%' class='forumheader3'>". $rs->form_text("upload_maxfilesize", 10, $pref['upload_maxfilesize'], 10)." 779 </td> 780 </tr> 781 782 <tr> 783 <td style='width:70%' class='forumheader3'>".UPLLAN_37."<br /> 784 <span class='smalltext'>".UPLLAN_38."</span></td> 785 <td style='width:30%' class='forumheader3'>".r_userclass("upload_class", $pref['upload_class'],"off","nobody,public,guest,member,admin,classes")." 786 787 </td> 788 </tr> 789 790 <tr> 791 <td colspan='2' class='forumheader' style='text-align:center'>". $rs->form_button("submit", "optionsubmit", LAN_SUBMIT)." 792 </td> 793 </tr> 794 </table>". $rs->form_close()." 795 </div>"; 796 797 $ns->tablerender(LAN_OPTIONS, $text); 798 break; 799 800 case 'view' : 801 $sql->db_Select('upload', '*', "upload_id='{$id}'"); 802 $row = $sql->db_Fetch(); 803 extract($row); 804 805 806 807 $post_author_id = substr($upload_poster, 0, strpos($upload_poster, ".")); 808 $post_author_name = substr($upload_poster, (strpos($upload_poster, ".")+1)); 809 $poster = (!$post_author_id ? "<b>".$post_author_name."</b>" : "<a href='".e_BASE."user.php?id.".$post_author_id."'><b>".$post_author_name."</b></a>"); 810 $upload_datestamp = $gen->convert_date($upload_datestamp, "long"); 811 812 $text = "<div style='text-align:center'> 813 <table style='".ADMIN_WIDTH."' class='fborder'> 814 <colgroup> 815 <col style='width:30%' /> 816 <col style='width:70%' /> 817 </colgroup> 818 819 <tr> 820 <td class='forumheader3'>".LAN_ID."</td> 821 <td class='forumheader3'>{$upload_id}</td> 822 </tr> 823 824 <tr> 825 <td class='forumheader3'>".LAN_DATE."</td> 826 <td class='forumheader3'>{$upload_datestamp}</td> 827 </tr> 828 829 <tr> 830 <td class='forumheader3'>".UPLLAN_5."</td> 831 <td class='forumheader3'>{$poster}</td> 832 </tr> 833 834 <tr> 835 <td class='forumheader3'>".UPLLAN_6."</td> 836 <td class='forumheader3'><a href='mailto:{$upload_email}'>{$upload_email}</td> 837 </tr> 838 839 <tr> 840 <td class='forumheader3'>".UPLLAN_7."</td> 841 <td class='forumheader3'>".($upload_website ? "<a href='{$upload_website}'>{$upload_website}</a>" : " - ")."</td> 842 </tr> 843 844 <tr> 845 <td class='forumheader3'>".LAN_FILE_NAME."</td> 846 <td class='forumheader3'>".($upload_name ? $upload_name: " - ")."</td> 847 </tr> 848 849 <tr> 850 <td class='forumheader3'>".LAN_VERSION."</td> 851 <td class='forumheader3'>".($upload_version ? $upload_version : " - ")."</td> 852 </tr> 853 854 <tr> 855 <td class='forumheader3'>".LAN_FILE."</td> 856 <td class='forumheader3'>".(is_numeric($upload_file) ? "Binary file ID ".$upload_file : "<a href='".e_SELF."?dl.{$upload_file}'>$upload_file</a>")."</td> 857 </tr> 858 859 <tr> 860 <td class='forumheader3'>".LAN_SIZE."</td> 861 <td class='forumheader3'>".$e107->parseMemorySize($upload_filesize)."</td> 862 </tr> 863 864 <tr> 865 <td class='forumheader3'>".LAN_SCREENSHOT."</td> 866 <td class='forumheader3'>".($upload_ss ? "<a href='".e_BASE."request.php?upload.".$upload_id."'>".$upload_ss."</a>" : " - ")."</td> 867 </tr> 868 869 <tr> 870 <td class='forumheader3'>".LAN_DESCRIPTION."</td> 871 <td class='forumheader3'>{$upload_description}</td> 872 </tr> 873 874 <tr> 875 <td class='forumheader3'>".UPLLAN_14."</td> 876 <td class='forumheader3'>".($upload_demo ? $upload_demo : " - ")."</td> 877 </tr> 878 879 <tr> 880 <td class='forumheader3'>".LAN_OPTIONS."</td> 881 <td class='forumheader3'><a href='".e_SELF."?dlm.{$upload_id}'>".UPLAN_COPYTODLM."</a> | <a href='".e_SELF."?news.{$upload_id}'>".UPLLAN_16."</a> | <a href='".e_SELF."?dis.{$upload_id}'>".UPLLAN_17."</a></td> 882 </tr> 883 884 </table> 885 </div>"; 886 887 $ns->tablerender(UPLLAN_18, $text); 888 // Intentionally fall through into list mode 889 890 case 'list' : 891 default : 892 $imgd = e_BASE.$IMAGES_DIRECTORY; 893 $text = "<div style='text-align:center'> 894 <table style='".ADMIN_WIDTH."' class='fborder'> 895 <colgroup> 896 <col style='width:5%' /> 897 <col style='width:20%' /> 898 <col style='width:15%' /> 899 <col style='width:20%' /> 900 <col style='width:25%' /> 901 <col style='width:10%' /> 902 <col style='width:50px;white-space:nowrap' /> 903 </colgroup> 904 <tr> 905 <td class='fcaption'>".LAN_ID."</td> 906 <td class='fcaption'>".LAN_DATE."</td> 907 <td class='fcaption'>".UPLLAN_5."</td> 908 <td class='fcaption'>".LAN_NAME."</td> 909 <td class='fcaption'>".LAN_FILE_NAME."</td> 910 <td class='fcaption'>".LAN_SIZE."</td> 911 <td class='fcaption'>".LAN_ACTIONS."</td> 912 </tr>"; 913 914 $text .= "<tr><td class='forumheader3' style='text-align:center' colspan='6'>"; 915 916 if (!$active_uploads = $sql->db_Select("upload", "*", "upload_active=0 ORDER BY upload_id ASC")) 917 { 918 $text .= UPLLAN_19.".\n</td>\n</tr>"; 919 } 920 else 921 { 922 $activeUploads = $sql -> db_getList(); 923 924 $text .= UPLLAN_20." ".($active_uploads == 1 ? UPLAN_IS : UPLAN_ARE).$active_uploads." ".($active_uploads == 1 ? UPLLAN_21 : UPLLAN_27)." ..."; 925 $text .= "</td></tr>"; 926 927 foreach($activeUploads as $row) 928 { 929 extract($row); 930 $post_author_id = substr($upload_poster, 0, strpos($upload_poster, ".")); 931 $post_author_name = substr($upload_poster, (strpos($upload_poster, ".")+1)); 932 $poster = (!$post_author_id ? "<b>".$post_author_name."</b>" : "<a href='".e_BASE."user.php?id.".$post_author_id."'><b>".$post_author_name."</b></a>"); 933 $upload_datestamp = $gen->convert_date($upload_datestamp, "short"); 934 $text .= "<tr> 935 <td class='forumheader3'>".$upload_id ."</td> 936 <td class='forumheader3'>".$upload_datestamp."</td> 937 <td class='forumheader3'>".$poster."</td> 938 <td class='forumheader3'><a href='".e_SELF."?view.".$upload_id."'>".$upload_name ."</a></td> 939 <td class='forumheader3'>".$upload_file ."</td> 940 <td class='forumheader3'>".$e107->parseMemorySize($upload_filesize)."</td> 941 <td class='forumheader3'> 942 <form action='".e_SELF."?dis.{$upload_id}' id='uploadform_{$upload_id}' method='post'> 943 <div><a href='".e_SELF."?dlm.{$upload_id}'><img src='".e_IMAGE."admin_images/downloads_16.png' alt='".UPLAN_COPYTODLS."' title='".UPLAN_COPYTODLS."' style='border:0' /></a> 944 <a href='".e_SELF."?news.{$upload_id}'><img src='".e_IMAGE."admin_images/news_16.png' alt='".UPLLAN_16."' title='".UPLLAN_16."' style='border:0' /></a> 945 <input type='image' title='".LAN_DELETE."' name='updelete[upload_{$upload_id}]' src='".ADMIN_DELETE_ICON_PATH."' onclick=\"return jsconfirm('".$tp->toJS(UPLLAN_45." [ {$upload_name} ]")."') \"/> 946 </div></form></td> 947 </tr>"; 948 } 949 } 950 $text .= "</table>\n</div>"; 951 952 $ns->tablerender(LAN_UPLOADS, $text); 953} // end - switch($action) 954 955 956 957 958function upload_adminmenu() 959{ 960 $action = (e_QUERY) ? e_QUERY : "list"; 961 962 $var['list']['text'] = UPLLAN_51; 963 $var['list']['link'] = e_SELF."?list"; 964 $var['list']['perm'] = "V"; 965 966 if(getperms("0")) 967 { 968 $var['filetypes']['text'] = LAN_FILETYPES; 969 $var['filetypes']['link'] = e_SELF."?filetypes"; 970 $var['filetypes']['perm'] = "0"; 971 972 $var['options']['text'] = LAN_OPTIONS; 973 $var['options']['link'] = e_SELF."?options"; 974 $var['options']['perm'] = "0"; 975 } 976 show_admin_menu(LAN_UPLOADS, $action, $var); 977} 978 979 980 981require_once("footer.php"); 982 983