pages/file.inc.php

Go to the documentation of this file.
00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php based project management system
00003 # Copyright (c) 2005 Thomas Mann - thomas@pixtur.de
00004 # Distributed under the terms and conditions of the GPL as stated in docs/license.txt
00005 
00014 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00015 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00016 require_once(confGet('DIR_STREBER') . 'db/class_file.inc.php');
00017 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00018 
00022 function fileView()
00023 {
00024     global $PH;
00025     global $auth;
00026     require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00027 
00028     ### get object ####
00029     $file_id= getOnePassedId('file');
00030     if(!$file= File::getVisibleById($file_id)) {
00031         $PH->abortWarning("invalid file-id",ERROR_FATAL);
00032     }
00033 
00034     $file_org= $file->getOriginal();
00035 
00036     if($file->is_latest) {
00037         $file_latest= $file;
00038     }
00039     else {
00040         $file_latest= $file->getLatest();
00041     }
00042 
00043     if(!$project= Project::getVisibleById($file->project)) {
00044         $PH->abortWarning("invalid project-id",ERROR_FATAL);
00045     }
00046 
00050     $parent_task = NULL;
00051     if($file->parent_item) {
00052         #trigger_error('@@@not implemented yet', E_USER_ERROR);
00053 
00054         if(!$parent_task = Task::getVisibleById(intval($file->parent_item))) {
00055             $PH->messages[]=sprintf(__("Could not access parent task Id:%s"), $file->parent_item);
00056         }
00057     }
00058 
00059     ### create from handle ###
00060     $from_handle= $PH->defineFromHandle(array('file'=>$file->id));
00061 
00062     ## is viewed by user ##
00063     $file->nowViewedByUser();
00064 
00065     ### set up page and write header ####
00066     {
00067         $page= new Page();
00068         $page->cur_tab='projects';
00069 
00070 
00071         $page->cur_crumb= 'projViewFiles';
00072         $page->crumbs= build_project_crumbs($project);
00073         $page->options= build_projView_options($project);
00074 
00075 
00076 /*        if($parent_task) {
00077             $page->crumbs=build_task_crumbs($parent_task);
00078         }
00079         else {
00080             $page->crumbs=build_project_crumbs($project);
00081         }
00082         $page->crumbs[]=new NaviCrumb(array(
00083             'target_id' => 'projViewFiles',
00084             'target_params'=>array('prj'=>$project->id),
00085         ));
00086         $page->crumbs[]=new NaviCrumb(array(
00087             'target_id' => 'fileView',
00088             'target_params'=>array('file'=>$file->id),
00089             'name'=>$file->name,
00090 
00091         ));
00092         */
00093 
00094 
00095         $page->type= __('File');
00096 
00097         if($parent_task) {
00098 
00099             if($folder= $parent_task->getFolderLinks()) {
00100                 $page->type= $folder;
00101             }
00102             $page->type.= " &gt; ". $parent_task->getLink() . " &gt; " . __('File');
00103         }
00104 
00105 
00106 
00107         $page->title=$file_org->name;
00108         $page->title_minor=sprintf(__('Item-ID %d'), $file_org->id);;
00109         if($file->state== -1) {
00110             $page->title_minor=sprintf(__('(deleted %s)','page title add on with date of deletion'),renderTimestamp($file->deleted));
00111         }
00112 
00113         ### page functions ###
00114         $page->add_function(new PageFunction(array(
00115             'target'=>'fileEdit',
00116             'params'=>array('file'=>$file->id),
00117             'icon'=>'edit',
00118             'tooltip'=>__('Edit this file'),
00119             'name'=>__('Edit')
00120         )));
00121 
00122         $page->add_function(new PageFunction(array(
00123             'target'=>'filesMoveToFolder',
00124             'params'=>array("file"=>$file->id),
00125             'tooltip'=>__('Move this file to another task'),
00126             'name'=>__('Move')
00127         )));
00128         
00129         $item = ItemPerson::getAll(array('person'=>$auth->cur_user->id,'item'=>$file->id));
00130         if((!$item) || ($item[0]->is_bookmark == 0)){
00131             $page->add_function(new PageFunction(array(
00132                 'target'    =>'itemsAsBookmark',
00133                 'params'    =>array('file'=>$file->id),
00134                 'tooltip'   =>__('Mark this file as bookmark'),
00135                 'name'      =>__('Bookmark'),
00136             )));
00137         }
00138         else{
00139             $page->add_function(new PageFunction(array(
00140                 'target'    =>'itemsRemoveBookmark',
00141                 'params'    =>array('file'=>$file->id),
00142                 'tooltip'   =>__('Remove this bookmark'),
00143                 'name'      =>__('Remove Bookmark'),
00144             )));
00145         } 
00146 
00147 
00148         ### render title ###
00149         echo(new PageHeader);
00150     }
00151     echo (new PageContentOpen);
00152 
00153 
00154     #--- upload new versions --------
00155     {
00156         $block=new PageBlock(array('title'=>__('Upload new version','block title'),'id'=>'summary'));
00157         $block->render_blockStart();
00158 
00159         echo "<div class=text>";
00160         echo '<input type="hidden" name="MAX_FILE_SIZE" value="'. confGet('FILE_UPLOAD_SIZE_MAX'). '" />';
00161         echo '<input id="userfile" name="userfile" type="file" size="40" accept="*" />';
00162         echo '<input type="submit" value="'.__('Upload').'" />';
00163         echo '</div>';
00164 
00165         $block->render_blockEnd();
00166 
00167     }
00168 
00169 
00170     #--- summary ----------------------------------------------------------------
00171     {
00172         $block=new PageBlock(array(
00173             'title'=>sprintf(__('Version #%s (current): %s'), $file_latest->version, $file_latest->name),
00174             'id'=>'description'
00175         ));
00176         $block->render_blockStart();
00177 
00178         echo "<div class=text>";
00179 
00180         ### show thumbnail
00181         if($file_latest->mimetype == "image/png" || $file_latest->mimetype == "image/jpeg" || $file_latest->mimetype == "image/gif") {
00182             echo "<div class=image style='float:right;'><a href='index.php?go=fileDownloadAsImage&amp;file=$file_latest->id'>";
00183             echo "<img src='index.php?go=fileDownloadAsImage&amp;file=$file_latest->id&amp;max_size=128'>";
00184             echo "</a></div>";
00185         }
00186 
00187         if($parent_task)  {
00188             echo "<p><label>" . __('For task') .  "</label><span>".$parent_task->getLink(false). "</span></p>";
00189         }
00190         echo "<p><label>" . __('Filesize') .  "</label><span>$file_latest->filesize bytes</span></p>";
00191         echo "<p><label>" . __('Type') .  "</label><span>$file_latest->mimetype</span></p>";
00192         echo "<p><label>" . __('Uploaded') .  "</label><span>". renderDateHtml($file_latest->created) ."</span></p>";
00193         if($uploader = Person::getVisibleById($file->created_by)) {
00194             echo "<p><label>" . __('Uploaded by') .  "</label><span>". $uploader->getLink()  ."</span></p>";
00195         }
00196         if($file_latest->created != $file_latest->modified) {
00197             echo "<p><label>" . __('Modified') .  "</label><span>". renderDateHtml($file_latest->created) ."</span></p>";
00198         }
00199         echo "<p><label>". __('Download'). "</label><span>". $PH->getLink('fileDownload', $file_latest->org_filename ,array('file'=>$file_latest->id))."</span></p>";
00200 
00201         $str= wiki2html($file_latest->description, $project);
00202         echo "<br>";
00203         echo "$str";
00204 
00205         echo "</div>";
00206 
00207 
00208 
00209         $block->render_blockEnd();
00210     }
00211 
00212     ### list previous versions ###
00213     {
00218         $old_files= File::getAll(array(
00219             'latest_only'   =>false,
00220             'org_file'      =>$file_org->id,
00221             'order_by'      =>'version DESC',
00222             'project'       =>$project->id,
00223         ));
00224         if($file_latest->id != $file_org->id) {
00225             $old_files[] = $file_org;
00226         }
00227 
00228         foreach($old_files as $of) {
00229             if($of->id != $file_latest->id) {
00230 
00231                 $block=new PageBlock(array(
00232                     'title'=>sprintf(__('Version #%s : %s'),$of->version, $of->name),
00233                     'id'=>'version_'.$of->id,
00234                 ));
00235                 $block->render_blockStart();
00236 
00237                 echo "<div class=text>";
00238 
00239                 ### show thumbnail
00240                 if($of->mimetype == "image/png" || $of->mimetype == "image/jpeg" || $of->mimetype == "image/gif") {
00241                     echo "<div class=image style='float:right;'><a href='index.php?go=fileDownloadAsImage&file=$of->id'>";
00242                     echo "<img src='index.php?go=fileDownloadAsImage&file=$of->id&max_size=128'>";
00243                     echo "</a></div>";
00244                 }
00245 
00246                 $str= wiki2html($of->description, $project);
00247                 echo "$str";
00248 
00249                 echo "<p><label>" . __('Filesize') .  "</label><span>$of->filesize bytes</span></p>";
00250                 echo "<p><label>" . __('Type') .  "</label><span>$of->mimetype</span></p>";
00251                 echo "<p><label>" . __('Uploaded') .  "</label><span>". renderDateHtml($of->created) ."</span></p>";
00252 
00253                 #echo "<p><label>" . __('Version') .  "</label><span>". intval($of->version) ."</span></p>";
00254                 echo "<p>". $PH->getLink('fileDownload','',array('file'=>$of->id))."</p>";
00255 
00256                 echo "</div>";
00257 
00258                 $block->render_blockEnd();
00259             }
00260         }
00261     }
00262 
00263 
00264 
00265     $PH->go_submit='fileUpdate';
00266 
00267 
00273     /*
00274     {
00275         $comments= $file->getComments();
00276         $list=new ListBlock_comments();
00277         $list->no_items_html=$PH->getLink('commentNew','',array('parent_task'=>$task->id));
00278         $list->render_list($comments);
00279     }
00280     */
00281 
00282     echo '<input type="hidden" name="prj"  value="'.$file->project.'">';
00283     echo '<input type="hidden" name="org_file" value="'.$file->id.'">';
00284 
00288     #echo '<input type="hidden" name="parent_task" value="'.$task->id.'">';
00289 
00290     echo (new PageContentClose);
00291     echo (new PageHtmlEnd);
00292 }
00293 
00294 
00300 function fileUpdate()
00301 {
00302     global $PH;
00303 
00304     ### first try single project-id ###
00305     $project=NULL;
00306     if($ids=getPassedIds('prj','projects_*')) {
00307         if(!$project= Project::getVisibleById($ids[0])) {
00308             $PH->abortWarning("ERROR: could not get Project", E_USER_WARNING);
00309             return;
00310         }
00311     }
00312 
00313 
00314     ### get original file ###
00315     if(!$updated_file= File::getEditableById(get('org_file'))) {
00316         $PH->abortWarning("ERROR: Can not find old file", E_USER_WARNING);
00317     }
00318     if(!$file_org= $updated_file->getOriginal()) {
00319         $PH->abortWarning("ERROR: Can not find old file", E_USER_WARNING);
00320     }
00321     if(!$file_latest= $updated_file->getLatest()) {
00322         $PH->abortWarning("ERROR: Can not find old file", E_USER_WARNING);
00323     }
00324 
00325     if(!$project) {
00326         if(!$project= Project::getVisibleById($file_org->project)) {
00327             $PH->abortWarning("Invalid project for task?", ERROR_BUG);
00328         }
00329     }
00330 
00331     $new_file= File::getUploaded();
00332     if(!$new_file) {
00333         $PH->abortWarning("Nothing uploaded");
00334     }
00335 
00336     ### build new object ###
00337     $new_file->project      = $project->id;
00338     $new_file->parent_item  = $file_org->parent_item;
00339     $new_file->org_file     = $file_org->id;
00340     $new_file->version      = $file_latest->version + 1;
00341 
00342     $PH->show('fileEdit',array('file'=>$new_file->id),$new_file);
00343 
00344 }
00345 
00346 
00352 function filesUpload()
00353 {
00354     global $PH;
00355 
00356     $new_file= File::getUploaded();
00357     if(!$new_file) {
00358         $PH->abortWarning("Nothing uploaded");
00359     }
00360 
00361     ### first try single project-id ###
00362     $project=NULL;
00363     if($ids=getPassedIds('prj','projects_*')) {
00364         if(!$project= Project::getVisibleById($ids[0])) {
00365             $PH->abortWarning("ERROR: could not get Project");
00366             return;
00367         }
00368     }
00369 
00370 
00371     ### try to get task ###
00372     $task_id=0;
00373     if($task_ids= getPassedIds('parent_task','tasks_*')) {
00374         if(count($task_ids) > 1) {
00375             $PH->messages[] = __("only expected one task. Used the first one.");
00376         }
00377         $task_id= $task_ids[0];
00378     }
00379 
00380 
00381     ### try to get folder ###
00382     else if($task_ids= getPassedIds('','folders_*')) {
00383         if(count($task_ids) > 1) {
00384             $PH->messages[] = __("only expected one task. Used the first one.");
00385         }
00386         $task_id= $task_ids[0];
00387     }
00388     if($task_id) {
00389         if($task= Task::getEditableById($task_id)) {
00390             $new_file->parent_item= $task->id;
00391         }
00392         else {
00393             $PH->abortWarning(__('Could not edit task'), ERROR_RIGHTS);
00394         }
00395     }
00396 
00397     if(!$project) {
00398         if( !$task_id) {
00399             $PH->abortWarning("Could not get project",ERROR_NOTE);
00400         }
00401         if(!$task= Task::getVisibleById($task_id)) {
00402             $PH->abortWarning("Invalid task id?", ERROR_BUG);
00403         }
00404         if(!$project= Project::getVisibleById($task->project)) {
00405             $PH->abortWarning("Invalid project for task?", ERROR_BUG);
00406         }
00407     }
00408 
00409     ### build new object ###
00410     $new_file->project = $project->id;
00411     $PH->show('fileEdit',array('file'=>$new_file->id),$new_file);
00412 }
00413 
00414 
00415 
00421 function fileEdit($file=NULL)
00422 {
00423     global $PH;
00424 
00425     if(!$file) {
00426         $id= getOnePassedId('file','files_*');   # WARNS if multiple; ABORTS if no id found
00427         if(!$file= File::getEditableById($id)) {
00428             $PH->abortWarning("ERROR: could not get File");
00429             return;
00430         }
00431     }
00432 
00433     if(!$project=Project::getVisibleById($file->project)) {
00434         $PH->abortWarning("ERROR: could not get Project",ERROR_BUG);
00435     }
00436 
00437     ### set up page and write header ####
00438     {
00439 
00440 
00441         $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'file_name'));
00442         $page->cur_tab='projects';
00443         $page->type=__('Edit File','page type');
00444         $page->title=$file->name;
00445 
00446         $page->crumbs= build_project_crumbs($project);
00447 
00448         $page->crumbs[]= new NaviCrumb(array(
00449             'target_id' => 'fileEdit',
00450         ));
00451 
00452         if($file->id) {
00453             $page->title=__('Edit File','page title');
00454         }
00455         else {
00456             $page->title=__('New File','page title');
00457         }
00458 
00459         $page->title_minor= sprintf(__('On project %s','page title add on'),$project->name);
00460 
00461 
00462         echo(new PageHeader);
00463     }
00464     echo (new PageContentOpen);
00465 
00466     $block=new PageBlock(array(
00467         'id'    =>'edit',
00468         'reduced_header' => true,
00469     ));
00470     $block->render_blockStart();
00471 
00472     ### write form #####
00473     {
00474         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00475 
00476         $form=new PageForm();
00477         $form->button_cancel=true;
00478 
00479         $form->add($file->fields['name']->getFormElement(&$file));
00480 
00481         $form->add($file->fields['description']->getFormElement(&$file));
00482 
00486         if($file->id == 0) {
00487             $form->add(new Form_HiddenField('file_mimetype',        '',urlencode($file->mimetype)));
00488             $form->add(new Form_HiddenField('file_filesize',        '',intval($file->filesize)));
00489             $form->add(new Form_HiddenField('file_org_filename',    '',urlencode($file->org_filename)));
00490             $form->add(new Form_HiddenField('file_tmp_filename',    '',urlencode($file->tmp_filename)));
00491             $form->add(new Form_HiddenField('file_tmp_dir',         '',$file->tmp_dir));
00492             $form->add(new Form_HiddenField('file_is_image',        '',$file->is_image));
00493             $form->add(new Form_HiddenField('file_version',         '',$file->version));
00494             $form->add(new Form_HiddenField('file_parent_item',     '',$file->parent_item));
00495             $form->add(new Form_HiddenField('file_org_file',        '',$file->org_file));
00496         }
00497         $form->add(new Form_HiddenField('file',             '',$file->id));
00498         $form->add(new Form_HiddenField('file_project',     '',$file->project));
00499 
00500 
00501 
00502         ### status ###
00503         {
00504             $st=array();
00505             global $g_status_names;
00506             foreach($g_status_names as $s=>$n) {
00507                 if($s >= STATUS_NEW) {
00508                     $st[$s]=$n;
00509                 }
00510             }
00511             $form->add(new Form_Dropdown('file_status',"Status",array_flip($st),  $file->status));
00512         }
00513 
00514         ### public-level ###
00515         if(($pub_levels= $file->getValidUserSetPublevel())
00516             && count($pub_levels)>1) {
00517             $form->add(new Form_Dropdown('file_pub_level',  __("Publish to"),$pub_levels,$file->pub_level));
00518         }
00519 
00520         echo ($form);
00521 
00522         $PH->go_submit='fileEditSubmit';
00523     }
00524     $block->render_blockEnd();
00525 
00526     echo (new PageContentClose);
00527     echo (new PageHtmlEnd);
00528 }
00529 
00530 
00536 function fileEditSubmit()
00537 {
00538     global $PH;
00539 
00540     ### cancel ###
00541 
00542     if(get('form_do_cancel')) {
00543         if(!$PH->showFromPage()) {
00544             $PH->show('projView',array('prj'=>$file->project));
00545         }
00546         exit();
00547     }
00548 
00549     $id=getOnePassedId('file');
00550 
00551 
00552     ### temp new file-object ####
00553     if($id == 0) {
00554         $file= new File(array('id'=>0));
00555 
00556         $file->mimetype= get('file_mimetype')
00557             ? urldecode(get('file_mimetype'))
00558             : NULL;
00559 
00560         $file->org_filename= get('file_org_filename')
00561                         ? urldecode(get('file_org_filename'))
00562                         : NULL;
00563 
00564         $file->tmp_filename= get('file_tmp_filename')
00565                         ? urldecode(get('file_tmp_filename'))
00566                         : NULL;
00567 
00568         $file->tmp_dir= get('file_tmp_dir')
00569                         ? get('file_tmp_dir')
00570                         : NULL;
00571 
00572 
00573         ### make sure file is not already uploaded ###
00574         #if(!file_exists("_uploads/". $file->tmp_dir)) {
00575         #    $PH->abortWarning("Not again");
00576         #}
00577 
00578 
00579         $file->filesize= intval(get('file_filesize'));
00580 
00581         $file->is_image     = intval(get('file_is_image'));
00582         $file->version      = intval(get('file_version'));
00583         $file->parent_item  = intval(get('file_parent_item'));
00584         $file->org_file     = intval(get('file_org_file'));
00585     }
00586     ### from database ###
00587     else {
00588         $file= File::getEditableById($id);
00589         if(!$file) {
00590             $PH->abortWarning(__("Could not get file"));
00591             return;
00592         }
00593     }
00594 
00595     $file->project=get('file_project');
00596     if(!$project = Project::getVisibleById($file->project)) {
00597         $PH->abortWarning(__("Could not get project of file"));
00598     }
00599 
00600 
00601     if(!is_null(get('file_name'))) {
00602         $file->name= get('file_name');
00603     }
00604 
00605     if(!is_null(get('file_description'))) {
00606         $file->description= get('file_description');
00607     }
00608 
00609     if(!is_null(get('file_status'))) {
00610         $file->status= get('file_status');
00611     }
00612 
00613     ### pub level ###
00614     if($pub_level=get('file_pub_level')) {
00615 
00616         ### not a new file ###
00617         if($file->id) {
00618              if($pub_level > $file->getValidUserSetPublevel() ) {
00619                  $PH->abortWarning('invalid data',ERROR_RIGHTS);
00620              }
00621         }
00622         else {
00623             #@@@ check for person create rights
00624             $foo= true;
00625         }
00626         $file->pub_level = $pub_level;
00627     }
00628 
00629 
00630     ### go back to from if validation fails ###
00631     $failure= false;
00632     if($file->name == "") {
00633         $failure= true;
00634         $PH->messages[]=__("Please enter a proper filename");
00635     }
00636 
00637     if($failure) {
00638         $PH->show('fileEdit',NULL,$file);
00639         exit();
00640     }
00641 
00642     ### write to db ###
00643     if($file->id == 0) {
00644 
00645         $latest_file= NULL;
00646         if($file->org_file) {
00647             if(!$org_file= File::getEditableById($file->org_file)) {                
00648                 $PH->abortWarning("unable to write parent file", ERROR_RIGHTS);
00649             }
00650             if(!$latest_file= $org_file->getLatest()) {
00651                 $PH->abortWarning("unable to get latest file", ERROR_RIGHTS);
00652             }            
00653         }
00654 
00655         if(!$file->insert()) {
00656             $PH->abortWarning("Could not insert file to db");
00657         }
00658 
00659         ### updated former latest file? ###
00660         if($latest_file) {                
00661             $latest_file->is_latest= 0;
00662             $latest_file->update();                    
00663         }               
00664     }
00665     else {
00666         $file->update();
00667     }
00668 
00669     ### update date of parent items ? ###
00670     if($item= DbProjectItem::getEditableById($file->parent_item)) {
00671         $item->update(array());        
00672     }
00673 
00674     ### display taskView ####
00675     if(!$PH->showFromPage()) {
00676         $PH->show('projView',array('prj'=>$file->project));
00677     }
00678 }
00679 
00680 
00684 function filesDelete()
00685 {
00686     global $PH;
00687 
00688     ### get file ####
00689     $ids= getPassedIds('file','files_*');
00690 
00691     if(!$ids) {
00692         $PH->abortWarning(__("Select some files to delete"));
00693         return;
00694     }
00695 
00696     $counter=0;
00697     $errors=0;
00698     foreach($ids as $id) {
00699         $f= file::getEditableById($id);
00700         if(!$f) {
00701             $PH->abortWarning("Invalid file-id!");
00702         }
00703         if($f->delete()) {
00704             $counter++;
00705         }
00706         else {
00707             $errors++;
00708         }
00709     }
00710     if($errors) {
00711         $PH->messages[]=sprintf(__("Failed to delete %s files"), $errors);
00712     }
00713     else {
00714         $PH->messages[]=sprintf(__("Moved %s files to trash"),$counter);
00715     }
00716 
00717     if(!$PH->showFromPage()) {
00718         $PH->show('projView',array('prj'=>$file->project));
00719     }
00720 }
00721 
00722 
00727 function fileDownload()
00728 {
00729 
00730     ### get file ####
00731     $id= getOnePassedId('file','files_*');
00732 
00733     if(!$file= File::getVisibleById($id)) {
00734         global $PH;
00735         $PH->abortWarning(__("Select some file to display"));
00736         return;
00737     }
00738     $file->download();
00739 }
00740 
00745 function fileDownloadAsImage()
00746 {
00747 
00748     ### get file ####
00749     $id= getOnePassedId('file','files_*');
00750 
00751     if(!$file= File::getVisibleById($id)) {
00752         $PH->abortWarning(__("Select some file to display"));
00753         return;
00754     }
00755 
00756     if($max_size = get('max_size')) {
00757         $file->viewAsImage($max_size);
00758     }
00759     else {
00760         $file->view();
00761     }
00762 }
00763 
00764 
00765 
00766 
00767 
00768 
00769 
00770 
00771 
00772 
00785 function FilesMoveToFolder()
00786 {
00787     global $PH;
00788 
00789     $file_ids= getPassedIds('file','files_*');
00790 
00791     if(!$file_ids) {
00792         $PH->abortWarning(__("Select some files to move"));
00793         exit();
00794     }
00795 
00796 
00797 
00801     $target_id=-1;
00802 
00806     $folder_ids= getPassedIds('folder','folders_*');
00807     if(count($folder_ids) == 1) {
00808         if($folder_task= Task::getVisibleById($folder_ids[0])) {
00809             $target_id= $folder_task->id;
00810         }
00811     }
00812 
00816     else if(get('from_selection')) {
00817         $target_id= 0;
00818     }
00819 
00820 
00821     if($target_id != -1) {
00822 
00823 
00824         if($target_id != 0){
00825             if(!$target_task= Task::getEditableById($target_id)) {
00826                 $PH->abortWarning(__("insufficient rights"));
00827 
00828             }
00829             ### get path of target to check for cycles ###
00830             $parent_tasks= $target_task->getFolder();
00831             $parent_tasks[]= $target_task;
00832         }
00833         else {
00834             $parent_tasks=array();
00835         }
00836 
00837 
00838         $count=0;
00839         foreach($file_ids as $id) {
00840             if($file= File::getEditableById($id)) {
00841 
00842                 $file->parent_item= $target_id;
00843                 $file->update();
00844             }
00845             else {
00846                 $PH->messages[]= sprintf(__("Can not edit file %s"), $file->name);
00847             }
00848         }
00849 
00850         ### return to from-page? ###
00851         if(!$PH->showFromPage()) {
00852             $PH->show('home');
00853         }
00854         exit();
00855     }
00856     #else if($target_id != -1) {
00857     #    $PH->abortWarning(__("insufficient rights to edit any of the selected items"));
00858     #}
00859 
00860 
00861 
00862 
00867     ### get project ####
00868     if(!$file= File::getVisibleById($file_ids[0])) {
00869         $PH->abortWarning("could not get file", ERROR_BUG);
00870     }
00871 
00872     if(!$project= Project::getVisibleById($file->project)) {
00873         $PH->abortWarning("file without project?", ERROR_BUG);
00874     }
00875 
00876 
00877     ### set up page and write header ####
00878     {
00879         $page= new Page(array('use_jscalendar'=>false, 'autofocus_field'=>'company_name'));
00880         $page->cur_tab='projects';
00881         $page->type= __("Edit files");
00882         $page->title="$project->name";
00883         $page->title_minor=__("Select folder to move files into");
00884 
00885         $page->crumbs= build_project_crumbs($project);
00886 
00887         $page->options[]= new NaviOption(array(
00888             'target_id'     =>'filesMoveToFolder',
00889         ));
00890 
00891         echo(new PageHeader);
00892     }
00893     echo (new PageContentOpen);
00894 
00895 
00896     ### write form #####
00897     {
00898         ### write files as hidden entry ###
00899         foreach($file_ids as $id) {
00900             if($file= File::getEditableById($id)) {
00901                 echo "<input type=hidden name='files_{$id}_chk' value='1'>";
00902             }
00903         }
00904 
00905 
00906         ### write list of folders ###
00907         {
00908             require_once(confGet('DIR_STREBER') . 'lists/list_tasks.inc.php');
00909             $list= new ListBlock_tasks();
00910             $list->reduced_header= true;
00911             $list->query_options['show_folders']= true;
00912             #$list->query_options['folders_only']= true;
00913             $list->query_options['project']= $project->id;
00914             $list->groupings= NULL;
00915             $list->block_functions= NULL;
00916             $list->id= 'folders';
00917             $list->no_items_html= __('No folders available');
00918             unset($list->columns['status']);
00919             unset($list->columns['date_start']);
00920             unset($list->columns['days_left']);
00921             unset($list->columns['created_by']);
00922             unset($list->columns['label']);
00923             unset($list->columns['project']);
00924 
00925             $list->functions= array();
00926 
00927             $list->active_block_function = 'tree';
00928 
00929 
00930             $list->print_automatic($project,NULL);
00931         }
00932 
00933         echo __("(or select nothing to move to project root)"). "<br> ";
00934 
00935         echo "<input type=hidden name='from_selection' value='1'>";             # keep flag to ungroup files
00936         echo "<input type=hidden name='project' value='$project->id'>";
00937         $button_name=__("Move items");
00938         echo "<input class=button2 type=submit value='$button_name'>";
00939 
00940         $PH->go_submit='filesMoveToFolder';
00941 
00942     }
00943     echo (new PageContentClose);
00944     echo (new PageHtmlEnd());
00945 
00946 }
00947 
00948 ?>

Generated on Sun Mar 4 17:19:31 2007 for streber by  doxygen 1.5.1-p1