From f9107de6ac37fd449a15daa7923d98e0be288b53 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 4 Oct 2001 00:46:06 +0000 Subject: [PATCH] Attachment of Uploaded files (stored under /infolog via VFS) based on the patch of juergen@henge-ernst.de --- infolog/inc/class.uiinfolog.inc.php | 220 ++++++++++++++++-- infolog/setup/phpgw_de.lang | 15 +- infolog/setup/phpgw_en.lang | 15 +- infolog/templates/default/add_file.tpl | 49 ++++ infolog/templates/default/delete.tpl | 2 +- infolog/templates/default/form.tpl | 14 +- infolog/templates/default/images/addfile.gif | Bin 0 -> 193 bytes infolog/templates/default/list.tpl | 6 +- .../templates/idsociety/images/addfile.gif | Bin 0 -> 193 bytes 9 files changed, 281 insertions(+), 40 deletions(-) create mode 100644 infolog/templates/default/add_file.tpl create mode 100644 infolog/templates/default/images/addfile.gif create mode 100644 infolog/templates/idsociety/images/addfile.gif diff --git a/infolog/inc/class.uiinfolog.inc.php b/infolog/inc/class.uiinfolog.inc.php index e82dd847d1..82ae10fdd5 100644 --- a/infolog/inc/class.uiinfolog.inc.php +++ b/infolog/inc/class.uiinfolog.inc.php @@ -17,40 +17,46 @@ { var $public_functions = array ( - 'get_list' => True, - 'view' => True, - 'add' => True, - 'edit' => True, - 'delete' => True, + 'get_list' => True, + 'view' => True, + 'add' => True, + 'edit' => True, + 'delete' => True, + 'get_file' => True, + 'add_file' => True, 'preferences' => True ); var $icons; + var $vfs; + var $basedir='/infolog'; function uiinfolog( ) { $this->bo = CreateObject('infolog.boinfolog'); + $this->vfs = CreateObject('phpgwapi.vfs'); $this->icons = array( 'type' => array( - 'task' => 'task.gif', 'task_alt' => 'Task', - 'phone' => 'phone.gif', 'phone_alt' => 'Phonecall', - 'note' => 'note.gif', 'note_alt' => 'Note', - 'confirm' => 'confirm.gif','confirm_alt' => 'Confirmation', - 'reject' => 'reject.gif', 'reject_alt' => 'Reject', - 'email' => 'email.gif', 'email_alt' => 'Email' ), + 'task' => 'task.gif', 'task_alt' => 'Task', + 'phone' => 'phone.gif', 'phone_alt' => 'Phonecall', + 'note' => 'note.gif', 'note_alt' => 'Note', + 'confirm' => 'confirm.gif', 'confirm_alt' => 'Confirmation', + 'reject' => 'reject.gif', 'reject_alt' => 'Reject', + 'email' => 'email.gif', 'email_alt' => 'Email' ), 'action' => array( - 'new' => 'new.gif', 'new_alt' => 'Add Sub', - 'view' => 'view.gif', 'view_alt' => 'View Subs', - 'parent' => 'parent.gif', 'parent_alt' => 'View other Subs', - 'edit' => 'edit.gif', 'edit_alt' => 'Edit', - 'delete' => 'delete.gif', 'delete_alt' => 'Delete' ), + 'new' => 'new.gif', 'new_alt' => 'Add Sub', + 'view' => 'view.gif', 'view_alt' => 'View Subs', + 'parent' => 'parent.gif', 'parent_alt' => 'View other Subs', + 'edit' => 'edit.gif', 'edit_alt' => 'Edit', + 'addfile' => 'addfile.gif', 'addfile_alt' => 'Add a file', + 'delete' => 'delete.gif', 'delete_alt' => 'Delete' ), 'status' => array( - 'billed' => 'billed.gif', 'billed_alt' => 'billed', - 'done' => 'done.gif', 'done_alt' => 'done', + 'billed' => 'billed.gif', 'billed_alt' => 'billed', + 'done' => 'done.gif', 'done_alt' => 'done', 'will-call' => 'will-call.gif', 'will-call_alt' => 'will-call', - 'call' => 'call.gif', 'call_alt' => 'call', - 'ongoing' => 'ongoing.gif','ongoing_alt' => 'ongoing', - 'offer' => 'offer.gif', 'offer_alt' => 'offer' ) + 'call' => 'call.gif', 'call_alt' => 'call', + 'ongoing' => 'ongoing.gif', 'ongoing_alt' => 'ongoing', + 'offer' => 'offer.gif', 'offer_alt' => 'offer' ) ); $this->filters = array( @@ -190,6 +196,20 @@ { $owner = "$owner"; } + + // add the links to the files which corrospond to this entry + $attachments=$this->vfs->ls($this->basedir.'/'.$info['info_id'].'/',array(REALTIVE_NONE)); + while (list($keys,$fileinfo) = each($attachments)) + { + $links .= isset($links) ? ', ' : '
'; + $links .= $this->html->a_href($fileinfo['name'],'/index.php', + $this->menuaction('get_file') + array( + 'info_id' => $info['info_id'], + 'filename' => $fileinfo['name']) + ); + if ($fileinfo['comment']) $links .= ' (' . $fileinfo['comment'] . ')'; + } + return array( 'type' => $this->icon('type',$info['info_type']), 'status' => $this->icon('status',$info['info_status']), @@ -197,12 +217,13 @@ 'subject' => $subject, 'des' => nl2br($info['info_des']), 'startdate' => $GLOBALS['phpgw']->common->show_date($info['info_startdate'], - $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), + $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), 'enddate' => $enddate, 'owner' => $owner, 'datecreated' => $GLOBALS['phpgw']->common->show_date($info['info_datecreated'], - $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), - 'responsible' => $responsible + $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), + 'responsible' => $responsible, + 'filelinks' => $links ); } @@ -252,7 +273,8 @@ global $cat_filter,$cat_id,$sort,$order,$query,$start,$filter; global $action,$addr_id,$proj_id,$info_id; - if (!$for_include) { + if (!$for_include) + { $GLOBALS['phpgw']->common->phpgw_header(); echo parse_navbar(); } @@ -419,6 +441,10 @@ $this->icon('action','edit'),'/index.php', $hidden_vars+array('info_id' => $id)+ $this->menuaction('edit'))); + $t->set_var('addfiles',$html->a_href( + $this->icon('action','addfile'),'/index.php', + $hidden_vars+array('info_id' => $id)+ + $this->menuaction('add_file'))); } else { @@ -485,6 +511,127 @@ $t->pfp('out','info_list_t',true); } + /* + ** Send a requested file to the user. + ** ACL check is done by the VFS + */ + function get_file( ) + { + $info_id=$GLOBALS['HTTP_GET_VARS']['info_id']; + $filename=$GLOBALS['HTTP_GET_VARS']['filename']; + + $browser = CreateObject('phpgwapi.browser'); + + $referer = $this->get_referer(); + + if (!$info_id || !$filename || !$this->bo->check_access($info_id,PHPGW_ACL_READ)) + { + Header('Location: ' . $html->link($referer)); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + $fn=$this->basedir.'/'.$info_id.'/'.$filename; + $browser->content_header($fn); + echo $this->vfs->read($fn,array(RELATIVE_ROOT)); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + /* + ** Put a file to the corrosponding place in the VFS and set the attributes + ** ACL check is done by the VFS + */ + function add_one_file($info_id,$filepos,$name,$size,$type,$comment='') + { + //echo "

add_one_file: info_id='$info_id', filepos='$filepos', name='$name', size='$size', type='$type', comment='$comment'

\n"; + + if ($filepos && ($filepos!="none") && $info_id) + { + // create the root for attached files in infolog, if it does not exists + if (!($this->vfs->file_exists($this->basedir,array(RELATIVE_ROOT)))) + { + $this->vfs->override_acl = 1; + $this->vfs->mkdir($this->basedir,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } + + if (!$this->vfs->securitycheck($filename)) + { + return lang('Invalid filename'); + } + else + { + $dir=$this->basedir.'/'.$info_id; + if (!($this->vfs->file_exists($dir,array(RELATIVE_ROOT)))) + { + $this->vfs->override_acl = 1; + $this->vfs->mkdir($dir,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } + $this->vfs->cp($filepos,$dir.'/'.$name,array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)); + $this->vfs->set_attributes ($dir.'/'.$name, array (RELATIVE_ROOT), + array ('mime_type' => $type, + 'comment' => stripslashes ($comment), + 'app' => 'infolog')); + } + } + } + + /* + ** Display dialog to add one file to an info_log entry + */ + function add_file( ) + { + global $upload,$info_id; + global $attachfile,$attachfile_name,$attachfile_size,$attachfile_type; + global $filecomment; + global $sort,$order,$query,$start,$filter,$cat_id,$referer; + + $t = $this->template; $html = $this->html; + $hidden_vars = array('sort' => $sort,'order' => $order, + 'query' => $query,'start' => $start, + 'filter' => $filter,'cat_id' => $cat_id ); + if (!isset($referer)) + $referer = $this->get_referer(); + + if (!isset($info_id) || !$info_id || !$this->bo->check_access($info_id,PHPGW_ACL_EDIT)) + { + $error[]=lang('Access denied'); + Header('Location: ' . $html->link($referer, $hidden_vars+array('cd'=>15))); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + if ($upload) { + $fileerror = $this->add_one_file($info_id,$attachfile,$attachfile_name,$attachfile_size,$attachfile_type,$filecomment); + if ($fileerror!='') $error[]=$fileerror; + } + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + + $t->set_file(array('info_add_file' => 'add_file.tpl')); + $t->set_var( $this->setStyleSheet( )); + $t->set_var( $this->infoHeaders( )); + $t->set_var( $this->formatInfo( $info_id )); + $t->set_var( 'hidden_vars',$html->input_hidden($hidden_vars+array('info_id' => $info_id))); + + if (is_array($error)) + { + $t->set_var('error_list',$GLOBALS['phpgw']->common->error_list($error)); + } + + $t->set_var('lang_info_action',lang('InfoLog').' - '.lang('attach file')); + + $t->set_var('actionurl',$html->link('/index.php',array('menuaction' => 'infolog.uiinfolog.add_file'))); + + $t->set_var('lang_file',lang('attach file').':'); + $t->set_var('lang_comment',lang('comment').':'); + + $t->set_var('submit_button',$html->submit_button('upload','attach file')); + $t->set_var('cancel_button',$html->form_1button('cancel_button','Cancel','',$referer)); + + $t->pfp('out','info_add_file'); + } + + function edit( ) { global $cat_id,$sort,$order,$query,$start,$filter; @@ -494,6 +641,8 @@ global $dur_days,$eday,$emonth,$eyear; global $type,$from,$addr,$id_addr,$id_project,$subject,$des,$access; global $pri,$status,$confirm,$info_cat,$id_parent,$responsible; + global $attachfile,$attachfile_name,$attachfile_size,$attachfile_type; + global $filecomment; $t = $this->template; $html = $this->html; @@ -614,10 +763,16 @@ 'id_parent' => $id_parent, 'responsible' => $responsible )); + + // save the attached file + $fileerror = $this->add_one_file($this->bo->so->data['info_id'],$attachfile,$attachfile_name,$attachfile_size,$attachfile_type,$filecomment); + if ($fileerror!='') $error[]=$fileerror; } + if (!$query_addr && !$query_project) { Header('Location: ' . $html->link($referer, array('cd'=>15))); + $GLOBALS['phpgw']->common->phpgw_exit(); } } } @@ -782,6 +937,9 @@ if (!isset($access)) $access = $this->bo->so->data['info_access'] == 'private'; $t->set_var('access_list',$html->checkbox('access',$access)); + $t->set_var('lang_file',lang('attach file').':'); + $t->set_var('lang_comment',lang('comment').':'); + $t->set_var('edit_button',$html->submit_button('save','Save')); if (!$action && $this->bo->check_access($info_id,PHPGW_ACL_DELETE)) @@ -814,12 +972,24 @@ !$this->bo->check_access($info_id,PHPGW_ACL_DELETE)) { Header('Location: ' . $html->link($referer)); + $GLOBALS['phpgw']->common->phpgw_exit(); } if ($confirm) { $this->bo->delete($info_id); Header('Location: ' . $html->link($referer,array( 'cd' => 16 ))); + + /* + ** Also remove the attached files for that entry + */ + $dir=$this->basedir.'/'.$info_id; + if ($this->vfs->file_exists($dir,array(RELATIVE_ROOT))) + { + $this->vfs->override_acl = 1; + $this->vfs->delete($dir,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } } else { diff --git a/infolog/setup/phpgw_de.lang b/infolog/setup/phpgw_de.lang index a6580f164b..526dbaa8dc 100644 --- a/infolog/setup/phpgw_de.lang +++ b/infolog/setup/phpgw_de.lang @@ -1,16 +1,21 @@ %1 records imported infolog de %1 Datensätze importiert %1 records read (not yet imported, you may go back and uncheck test import) infolog de %1 Datensätze gelesen (noch nicht importiert, sie können %2zurück%3 gehen und Test Import ausschalten) +Add a file infolog de Datei anhängen +Invalid filename infolog de Ungültiger Dateiname accept infolog de bei Annahme action infolog de Befehle add infolog de Hinzufügen add sub infolog de neues Teilprojekt anlegen all infolog de alle are you sure you want to delete this entry infolog de Sind Sie sicher, dass Sie diesen Eintrag löschen wollen? +attach file infolog de Datei anhängen back to projectlist infolog de Zurück zur Gesamtliste billed infolog de abgerechnet both infolog de Annahme+erledigt call infolog de anrufen category infolog de Kategorie +close infolog de Schließen +comment infolog de Kommentar confirm infolog de Bestätigung csv-fieldname infolog de CSV-Feldname csv-filename infolog de CSV-Dateiname @@ -30,20 +35,20 @@ fieldseparator infolog de Feldbegrenzer finish infolog de wenn erledigt from infolog de Von import infolog de Import -infolog - import csv-file infolog de InfoLog - Import CSV-Datei +infolog common de InfoLog infolog - delete infolog de InfoLog - Löschen infolog - edit infolog de InfoLog - Bearbeiten +infolog - import csv-file infolog de InfoLog - Import CSV-Datei infolog - new infolog de InfoLog - Anlegen infolog - new subproject infolog de InfoLog - Anlegen Teilprojekt infolog - subprojects from infolog de InfoLog - Teilprojekte von -infolog-fieldname infolog de InfoLog-Feldname -infolog common de InfoLog infolog preferences common de InfoLog Einstellungen +infolog-fieldname infolog de InfoLog-Feldname last changed infolog de letzte Änderung list no Subs/Childs infolog de Teilprojekte/Antwortdokumente nicht anzeigen no - cancel infolog de Nein - Abbruch -no filter infolog de kein Filter no entries found, try again ... infolog de Kein Einträge gefunden, nochmal versuchen ... +no filter infolog de kein Filter none infolog de keine not infolog de nicht not assigned infolog de nicht zugewiesen @@ -63,9 +68,9 @@ pattern for search in projects infolog de Muster f phone infolog de Anruf phone/email infolog de Telefon/Email phonecall infolog de Telefonanruf -project infolog de Projekt priority infolog de Priorität private infolog de Privat +project infolog de Projekt re: infolog de Re: reject infolog de Absage responsible infolog de Auftrag an diff --git a/infolog/setup/phpgw_en.lang b/infolog/setup/phpgw_en.lang index b0845b507f..e7743aba7b 100644 --- a/infolog/setup/phpgw_en.lang +++ b/infolog/setup/phpgw_en.lang @@ -1,16 +1,21 @@ %1 records imported infolog en %1 records imported %1 records read (not yet imported, you may go back and uncheck test import) infolog en %1 records read (not yet imported, you may go %2back%3 and uncheck Test Import) +Add a file infolog de Add a file +Invalid filename infolog de Invalid filename accept infolog en accept action infolog en Action add infolog en Add add sub infolog en add Sub all infolog en All are you sure you want to delete this entry infolog en Are you sure you want to delete this entry +attach file infolog en Attach file back to Projectlist infolog en Back to Projectlist billed infolog en billed both infolog en both call infolog en call category infolog en Category +close infolog de Close +comment infolog en Comment confirm infolog en confirm csv-fieldname infolog en CSV-Fieldname csv-filename infolog en CSV-Filename @@ -30,20 +35,20 @@ fieldseparator infolog en Fieldseparator finish infolog en finish from infolog en From import infolog en Import -infolog - import CSV-File infolog en InfoLog - Import CSV-File +infolog common en InfoLog infolog - delete infolog en Info Log - Delete infolog - edit infolog en InfoLog - Edit +infolog - import CSV-File infolog en InfoLog - Import CSV-File infolog - new infolog en InfoLog - New infolog - new subproject infolog en InfoLog - New Subproject infolog - subprojects from infolog en InfoLog - Subprojects from -infolog-fieldname infolog en Info Log-Fieldname -infolog common en InfoLog infolog preferences common en InfoLog preferences +infolog-fieldname infolog en Info Log-Fieldname last changed infolog en last changed list no Subs/Childs infolog en List no Subs/Childs no - cancel infolog en No - Cancel -no filter infolog en no Filter no entries found, try again ... infolog en no entries found, try again ... +no filter infolog en no Filter none infolog en None not infolog en not not assigned infolog en not assigned @@ -63,9 +68,9 @@ pattern for search in projects infolog en pattern for search in Projects phone infolog en Phonecall phone/email infolog en Phone/Email phonecall infolog en Phonecall -project infolog en Project priority infolog en Priority private infolog en Private +project infolog en Project re: infolog en Re: reject infolog en reject responsible infolog en Responsible diff --git a/infolog/templates/default/add_file.tpl b/infolog/templates/default/add_file.tpl new file mode 100644 index 0000000000..bd7be1041a --- /dev/null +++ b/infolog/templates/default/add_file.tpl @@ -0,0 +1,49 @@ +{info_css} +

{lang_info_action}
+ +

{error_list}
+
+
+ + + + + + + + + + + + + + + + + + + +
{lang_type}{lang_status}{lang_subject}{lang_startdate}{lang_enddate}{lang_owner}{lang_responsible}
{type}{status}{subject}
{des}{filelinks}
{startdate}{enddate}{owner}
{datecreated}
{responsible}

+ +

+
+ {hidden_vars} + + + + + + + + +
{lang_file}{lang_comment}
+

+ + + + + +
{submit_button}{cancel_button}
+

+
+ diff --git a/infolog/templates/default/delete.tpl b/infolog/templates/default/delete.tpl index 21ba03b482..c5c5ef988d 100644 --- a/infolog/templates/default/delete.tpl +++ b/infolog/templates/default/delete.tpl @@ -15,7 +15,7 @@ {type} {status} - {subject}
{des} + {subject}
{des}{filelinks} {startdate} {enddate} {owner}
{datecreated} diff --git a/infolog/templates/default/form.tpl b/infolog/templates/default/form.tpl index 0cd6ce669c..1ab019f3f1 100644 --- a/infolog/templates/default/form.tpl +++ b/infolog/templates/default/form.tpl @@ -6,7 +6,7 @@
{error_list}
-
+ {common_hidden_vars} @@ -61,6 +61,18 @@ + + + + + + + + + + + + diff --git a/infolog/templates/default/images/addfile.gif b/infolog/templates/default/images/addfile.gif new file mode 100644 index 0000000000000000000000000000000000000000..c45377c98e913cdadd81a0e3eace0de927294be5 GIT binary patch literal 193 zcmZ?wbhEHb6k!ly*v!E2|NsAU=g#fjySJyOCp|qqK0ZDuD9FppOI1~sg@uIytN=*D zf#OdVRuKkn1|5(H$P5OSyn>UStEVcxTzhh^q(WEZqgus;37iRw)+#dJd^9g~*QJw% z3Z0FrrdqpNc1}w=8Pd_@oSGO?Ah(#|Xh=w{lBQyA;+?%}o1bhHt-5A(I%h+OU_tf9 iug`vQXGwM!*2*+X)d-m|b#`?#G068%m?$d9U=09ZDn?BJ literal 0 HcmV?d00001 diff --git a/infolog/templates/default/list.tpl b/infolog/templates/default/list.tpl index dbf275d2de..85c1ccac83 100644 --- a/infolog/templates/default/list.tpl +++ b/infolog/templates/default/list.tpl @@ -22,7 +22,7 @@ - + @@ -48,14 +48,14 @@ - + - + diff --git a/infolog/templates/idsociety/images/addfile.gif b/infolog/templates/idsociety/images/addfile.gif new file mode 100644 index 0000000000000000000000000000000000000000..c45377c98e913cdadd81a0e3eace0de927294be5 GIT binary patch literal 193 zcmZ?wbhEHb6k!ly*v!E2|NsAU=g#fjySJyOCp|qqK0ZDuD9FppOI1~sg@uIytN=*D zf#OdVRuKkn1|5(H$P5OSyn>UStEVcxTzhh^q(WEZqgus;37iRw)+#dJd^9g~*QJw% z3Z0FrrdqpNc1}w=8Pd_@oSGO?Ah(#|Xh=w{lBQyA;+?%}o1bhHt-5A(I%h+OU_tf9 iug`vQXGwM!*2*+X)d-m|b#`?#G068%m?$d9U=09ZDn?BJ literal 0 HcmV?d00001

{lang_file}{lang_comment}

{lang_start_date}: {start_select_date}
{type} {status}{subject}
{des}
{subject}
{des}{filelinks}
{startdate}
{enddate}
{owner}
{datecreated}
{responsible}
{type} {status}{subject}
{des}
{subject}
{des}{filelinks}
{startdate}
{enddate}
{owner}
{datecreated}
{responsible} {subadd} {viewsub} {viewparent}{edit} {delete}{edit} {delete} {addfiles}