home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / files / addedit.php next >
Encoding:
PHP Script  |  2004-01-08  |  6.5 KB  |  194 lines

  1. <?php /* FILES $Id: addedit.php,v 1.23 2004/01/08 17:26:55 gregorerhardt Exp $ */
  2. $file_id = intval( dPgetParam( $_GET, 'file_id', 0 ) );
  3.  
  4. // check permissions for this record
  5. $canEdit = !getDenyEdit( $m, $file_id );
  6. if (!$canEdit) {
  7.     $AppUI->redirect( "m=public&a=access_denied" );
  8. }
  9.  
  10. // load the companies class to retrieved denied companies
  11. require_once( $AppUI->getModuleClass( 'projects' ) );
  12.  
  13. $file_task = intval( dPgetParam( $_GET, 'file_task', 0 ) );
  14. $file_parent = intval( dPgetParam( $_GET, 'file_parent', 0 ) );
  15. $file_project = intval( dPgetParam( $_GET, 'project_id', 0 ) );
  16.  
  17. $sql = "
  18. SELECT files.*,
  19.     user_username,
  20.     user_first_name,
  21.     user_last_name,
  22.     project_id,
  23.     task_id, task_name
  24. FROM files
  25. LEFT JOIN users ON file_owner = user_id
  26. LEFT JOIN projects ON project_id = file_project
  27. LEFT JOIN tasks ON task_id = file_task
  28. WHERE file_id = $file_id
  29. ";
  30.  
  31. // check if this record has dependancies to prevent deletion
  32. $msg = '';
  33. $obj = new CFile();
  34. $canDelete = $obj->canDelete( $msg, $file_id );
  35.  
  36. // load the record data
  37. $obj = null;
  38. if (!db_loadObject( $sql, $obj ) && $file_id > 0) {
  39.     $AppUI->setMsg( 'File' );
  40.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  41.     $AppUI->redirect();
  42. }
  43.  
  44. // setup the title block
  45. $ttl = $file_id ? "Edit File" : "Add File";
  46. $titleBlock = new CTitleBlock( $ttl, 'folder5.png', $m, "$m.$a" );
  47. $titleBlock->addCrumb( "?m=files", "files list" );
  48. if ($canEdit && $file_id > 0) {
  49.     $titleBlock->addCrumbDelete( 'delete file', $canDelete, $msg );
  50. }
  51. $titleBlock->show();
  52.  
  53. if ($obj->file_project) {
  54.     $file_project = $obj->file_project;
  55. }
  56. if ($obj->file_task) {
  57.     $file_task = $obj->file_task;
  58.     $task_name = @$obj->task_name;
  59. } else if ($file_task) {
  60.     $sql = "SELECT task_name FROM tasks WHERE task_id=$file_task";
  61.     $task_name = db_loadResult( $sql );
  62. } else {
  63.     $task_name = '';
  64. }
  65.  
  66. $extra = array(
  67.     'where'=>'AND project_active <> 0'
  68. );
  69. $project = new CProject();
  70. $projects = $project->getAllowedRecords( $AppUI->user_id, 'project_id,project_name', 'project_name', null, $extra );
  71. $projects = arrayMerge( array( '0'=>$AppUI->_('All') ), $projects );
  72.  
  73. //$sql = "SELECT project_id, project_name  FROM projects ORDER BY project_name";
  74. //$projects = arrayMerge( array( '0'=>'- ALL PROJECTS -'), db_loadHashList( $sql ) );
  75. ?>
  76. <script language="javascript">
  77. function submitIt() {
  78.     var f = document.uploadFrm;
  79.     f.submit();
  80. }
  81. function delIt() {
  82.     if (confirm( "<?php echo $AppUI->_('filesDelete');?>" )) {
  83.         var f = document.uploadFrm;
  84.         f.del.value='1';
  85.         f.submit();
  86.     }
  87. }
  88. function popTask() {
  89.     var f = document.uploadFrm;
  90.     if (f.file_project.selectedIndex == 0) {
  91.         alert( "<?php echo $AppUI->_('Please select a project first!');?>" );
  92.     } else {
  93.         window.open('./index.php?m=public&a=selector&dialog=1&callback=setTask&table=tasks&task_project='
  94.             + f.file_project.options[f.file_project.selectedIndex].value, 'task','left=50,top=50,height=250,width=400,resizable')
  95.     }
  96. }
  97.  
  98. // Callback function for the generic selector
  99. function setTask( key, val ) {
  100.     var f = document.uploadFrm;
  101.     if (val != '') {
  102.         f.file_task.value = key;
  103.         f.task_name.value = val;
  104.     } else {
  105.         f.file_task.value = '0';
  106.         f.task_name.value = '';
  107.     }
  108. }
  109. </script>
  110.  
  111. <table width="100%" border="0" cellpadding="3" cellspacing="3" class="std">
  112.  
  113. <form name="uploadFrm" action="?m=files" enctype="multipart/form-data" method="post">
  114.     <?php /* <input type="hidden" name="max_file_size" value="109605000" />
  115.         commented out (bug 863402), please delete if no errors and other developers agree */ ?>
  116.     <input type="hidden" name="dosql" value="do_file_aed" />
  117.     <input type="hidden" name="del" value="0" />
  118.     <input type="hidden" name="file_id" value="<?php echo $file_id;?>" />
  119.  
  120. <tr>
  121.     <td width="100%" valign="top" align="center">
  122.         <table cellspacing="1" cellpadding="2" width="60%">
  123.     <?php if ($file_id) { ?>
  124.         <tr>
  125.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'File Name' );?>:</td>
  126.             <td align="left" class="hilite"><?php echo strlen($obj->file_name)== 0 ? "n/a" : $obj->file_name;?></td>
  127.             <td>
  128.                 <a href="./fileviewer.php?file_id=<?php echo $obj->file_id;?>"><?php echo $AppUI->_( 'download' );?></a>
  129.             </td>
  130.         </tr>
  131.         <tr valign="top">
  132.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Type' );?>:</td>
  133.             <td align="left" class="hilite"><?php echo $obj->file_type;?></td>
  134.         </tr>
  135.         <tr>
  136.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Size' );?>:</td>
  137.             <td align="left" class="hilite"><?php echo $obj->file_size;?></td>
  138.         </tr>
  139.         <tr>
  140.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Uploaded By' );?>:</td>
  141.             <td align="left" class="hilite"><?php echo $obj->user_first_name . ' '. $obj->user_last_name;?></td>
  142.         </tr>
  143.     <?php } ?>
  144.         <tr>
  145.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Version' );?>:</td>
  146.             <td align="left">
  147.                 <input type="text" name="file_version" value="<?php echo strlen( $obj->file_version ) > 0 ? $obj->file_version : "1";?>" maxlength="10" size="5" />
  148.             </td>
  149.         </tr>
  150.  
  151.         <tr>
  152.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Project' );?>:</td>
  153.             <td align="left">
  154.             <?php
  155.                 echo arraySelect( $projects, 'file_project', 'size="1" class="text" style="width:270px"', $file_project  );
  156.             ?>
  157.             </td>
  158.         </tr>
  159.  
  160.         <tr>
  161.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Task' );?>:</td>
  162.             <td align="left" colspan="2" valign="top">
  163.                 <input type="hidden" name="file_task" value="<?php echo $file_task;?>" />
  164.                 <input type="text" class="text" name="task_name" value="<?php echo $task_name;?>" size="40" disabled />
  165.                 <input type="button" class="button" value="<?php echo $AppUI->_('select task');?>..." onclick="popTask()" />
  166.             </td>
  167.         </tr>
  168.  
  169.         <tr>
  170.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Description' );?>:</td>
  171.             <td align="left">
  172.                 <textarea name="file_description" class="textarea" rows="4" style="width:270px"><?php echo $obj->file_description;?></textarea>
  173.             </td>
  174.         </tr>
  175.  
  176.         <tr>
  177.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Upload File' );?>:</td>
  178.             <td align="left"><input type="File" class="button" name="formfile" style="width:270px"></td>
  179.         </tr>
  180.  
  181.         </table>
  182.     </td>
  183. </tr>
  184. <tr>
  185.     <td>
  186.         <input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel');?>" onClick="javascript:if(confirm('<?php echo $AppUI->_('Are you sure you want to cancel?'); ?>')){location.href = './index.php?m=files';}" />
  187.     </td>
  188.     <td align="right">
  189.         <input type="button" class="button" value="<?php echo $AppUI->_( 'submit' );?>" onclick="submitIt()" />
  190.     </td>
  191. </tr>
  192. </form>
  193. </table>
  194.