noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
action.common.inc.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /**\file
00024  * \brief this file is common to suivi client, suivi fournisseur, suivi
00025  * administration.
00026  * The needed variables are
00027  * - $cn for the database connection
00028  * - $sub_action sa from suivi courrier but sc from Suivi client, fournisseur...
00029  *
00030  */
00031 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00032 $supl_hidden = '';
00033 if (isset($_REQUEST['sc']))
00034         $supl_hidden.=HtmlInput::hidden('sc', $_REQUEST['sc']);
00035 if (isset($_REQUEST['f_id']))
00036         $supl_hidden.=HtmlInput::hidden('f_id', $_REQUEST['f_id']);
00037 if (isset($_REQUEST['sb']))
00038         $supl_hidden.=HtmlInput::hidden('sb', $_REQUEST['sb']);
00039 $supl_hidden.=HtmlInput::hidden('ac', $_REQUEST['ac']);
00040 $correction = 0;
00041 $error_id=0;
00042 /*-----------------------------------------------------------------------------*/
00043 /* For other action
00044 /*-----------------------------------------------------------------------------*/
00045 if ( isset ($_POST['other_action_bt'])) {
00046     /**
00047      * The action id are in the array mag_id
00048      * the tag to remove are vin the array remtag
00049      * the tag to add are in the array addtag
00050      * the state in ag_state
00051      */
00052     if (  isset ($_POST['mag_id'])) {
00053         switch ($_POST['othact']) {
00054             case 'IMP':
00055                 //Impression
00056                 Follow_Up::action_print($cn,$_POST);
00057                 return;
00058                 break;
00059             case 'ST':
00060                 // Etat
00061                 Follow_Up::action_set_state($cn, $_POST);
00062                 break;
00063             case 'ETIREM':
00064                 //tag
00065                 Follow_Up::action_tag_remove($cn, $_POST);
00066                 break;
00067             case 'ETIADD':
00068                 Follow_Up::action_tag_add($cn, $_POST);
00069                 break;
00070             case 'ETICLEAR':
00071                 Follow_Up::action_tag_clear($cn,$_POST);
00072                 break;
00073             case 'DOCREM':
00074                 Follow_Up::action_remove($cn, $_POST);
00075                 break;
00076         }
00077     }
00078 }
00079 
00080 /* --------------------------------------------------------------------------- */
00081 /* We ask to generate the document */
00082 /* --------------------------------------------------------------------------- */
00083 if (isset($_POST['generate']))
00084 {
00085         $act = new Follow_Up($cn);
00086         $act->fromArray($_POST);
00087         if ($act->ag_id == 0)
00088         {
00089                 $act->save();
00090                 $ag_id = $act->ag_id;
00091         }
00092         else
00093         {
00094                 $act->Update();
00095         }
00096         $act->generate_document($_POST['doc_mod'], $_POST);
00097         $sub_action = 'detail';
00098 }
00099 /* for delete  */
00100 if (isset($_POST['delete']))
00101         $sub_action = 'delete';
00102 if ($sub_action == "")
00103         $sub_action = "list";
00104 
00105 // if correction is asked go to directly to add_action
00106 if (isset($_POST['corr']))
00107 {
00108         $ag_comment = urldecode($_POST['ag_comment']);
00109         $sub_action = "add_action";
00110 }
00111 // if this page is called from another menu (customer, supplier,...)
00112 // a button back is added
00113 //----------------------------------------------------------------------
00114 // Update the detail
00115 // Add a new action related to this one or update
00116 //----------------------------------------------------------------------
00117 if ($sub_action == "update")
00118 {
00119         // Update the modification
00120         if (isset($_POST['save']))
00121         {
00122                 $act2 = new Follow_Up($cn);
00123                 $act2->fromArray($_POST);
00124                 if ($g_user->can_write_action($act2->ag_id) == false )
00125                 {
00126                         echo '<div class="redcontent">';
00127                         echo '<h2 class="error">'._('Cette action ne vous est pas autorisée Contactez votre responsable').'</h2>';
00128                         echo '</div>';
00129                         return;
00130                 }
00131                 $sub_action = "detail";
00132                 put_global(array(array('key' => "sa", "value" => "detail")));
00133                 try {
00134                     $act2->verify() ;
00135                     $act2->Update() ;
00136                 }
00137                 catch (Exception $e)
00138                 {
00139                     echo '<span class="notice">';
00140                     echo _("Erreur")." ".$e->getMessage();
00141                     echo '</span>';
00142                     $sub_action="detail";
00143                     $correction = 1;
00144                     $act = clone $act2;
00145                     $act->get();
00146                     $act->fromArray($_POST);
00147                     $error_id=$e->getCode();
00148                 }
00149         }
00150         //----------------------------------------------------------------------
00151         // Add a related action
00152         //----------------------------------------------------------------------
00153         if (isset($_POST['add_action_here']))
00154         {
00155                 $act = new Follow_Up($cn);
00156 
00157 
00158                 //----------------------------------------
00159                 // puis comme ajout normal (copier / coller )
00160                 $act->fromArray($_POST);
00161                 $act->ag_id = 0;
00162                 $act->d_id = 0;
00163                 $act->action = $_POST['ag_id'];
00164 
00165                 echo '<div class="content">';
00166 
00167                 // Add hidden tag
00168                 echo '<form  enctype="multipart/form-data" action="do.php" method="post"">';
00169 
00170                 $act->ag_comment = "";
00171                 if (isset($_REQUEST['qcode_dest']))
00172                         $act->qcode_dest = $_REQUEST['qcode_dest'];
00173                 echo $act->Display('NEW', false, $base, $retour);
00174 
00175                 echo '<input type="hidden" name="ac" value="' . $_REQUEST['ac'] . '">';
00176                 echo '<input type="hidden" name="sa" value="save_action_st2">';
00177                 echo '<input type="submit" class="button" name="save_action_st2" value="' . _('Enregistrer') . '">';
00178                 echo '<input type="submit" class="button" name="generate" value="' . _('Génère le document') . '"></p>';
00179                 echo $supl_hidden;
00180                 echo '</form>';
00181                 echo '</div>';
00182         }
00183 }
00184 //--------------------------------------------------------------------------------
00185 // Show the detail of an action
00186 // permit the update
00187 if ($sub_action == 'detail')
00188 {
00189         echo '<div class="content">';
00190         if ( $correction == 0 )
00191         {
00192             $act = new Follow_Up($cn);
00193             $act->ag_id = $ag_id;
00194             echo $act->get();
00195         }
00196         
00197         if ($g_user->can_write_action($ag_id)  == true)
00198         {
00199                 echo '<form  enctype="multipart/form-data"  class="print" action="do.php"  method="post"   >';
00200                 echo $supl_hidden;
00201                 echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00202                 echo dossier::hidden();
00203                 echo $act->Display('UPD', false, $base, $retour);
00204                 echo '<input type="hidden" name="sa" value="update">';
00205                 echo HtmlInput::submit("save", "Sauve");
00206                 echo HtmlInput::submit("add_action_here", _("Ajoute une action à celle-ci"));
00207                 echo HtmlInput::submit("delete", _("Efface cette action"), ' onclick="return confirm(\'' . _("Vous confirmez l\'effacement") . '\')" ');
00208                 echo $retour;
00209                 echo '</form>';
00210         }
00211         else if ($g_user->can_read_action($ag_id) == true || $act->ag_dest == -1)
00212         {
00213                 echo $act->Display('READ', false, $base, $retour);
00214         }
00215         else
00216         {
00217                 echo h2info(_("Ce document n'est pas accessible"));
00218                 return;
00219         }
00220 
00221 
00222         echo '</div>';
00223 }
00224 //-------------------------------------------------------------------------------
00225 // Delete an action
00226 if ($sub_action == 'delete')
00227 {
00228         // confirmed
00229         $cn->start();
00230         $act = new Follow_Up($cn);
00231         $act->ag_id = $_REQUEST['ag_id'];
00232         $act->get();
00233         if ($g_user->can_write_action($_REQUEST['ag_id'])==true)        $act->remove();
00234         $sub_action = "list";
00235         $cn->commit();
00236         Follow_Up::show_action_list($cn, $base);
00237         if (isset($act->ag_ref))
00238                 echo hb(_('Action ') . $act->ag_ref . _(' effacée'));
00239         return;
00240 }
00241 
00242 //--------------------------------------------------------------------------------
00243 // Show a list of the action
00244 if ($sub_action == "list")
00245 {
00246         // Add a button to export to Csv
00247         echo '<form method="GET" style="display:inline;" ACTION="export.php">';
00248         echo HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref", "remind_date","only_internal", "state", "gDossier", "qcode", "start_date", "end_date", "ag_id", "ag_dest_query",
00249                 "tdoc",   "action_query","date_start","date_end","hsstate","searchtag"));
00250         echo HtmlInput::hidden("act", "CSV:ActionGestion");
00251         echo HtmlInput::submit("follow_up_csv", "Export CSV",'','smallbutton');
00252         echo "</form>";
00253         Follow_Up::show_action_list($cn, $base);
00254 }
00255 //--------------------------------------------------------------------------------
00256 // Save Follow_Up
00257 // Stage 2 : Save a NEW action + Files and generate eventually a document
00258 //--------------------------------------------------------------------------------
00259 if ($sub_action == "save_action_st2")
00260 {
00261         $act = new Follow_Up($cn);
00262         $act->fromArray($_POST);
00263     try {
00264         $act->d_id = 0;
00265         $act->md_id = (isset($_POST['gen_doc'])) ? $_POST['gen_doc'] : 0;
00266 
00267         $act->verify();
00268         
00269         // insert into action_gestion
00270         echo $act->save();
00271         $url = "?$base&sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get();
00272         echo '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action Sauvée').'  : ' . $act->ag_ref) . '</a></p>';
00273 
00274         Follow_Up::show_action_list($cn,$base);
00275         $url = "?$base&sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get();
00276         echo '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action Sauvée').'  : ' . $act->ag_ref) . '</a></p>';
00277     } catch (Exception $e)
00278     {
00279         echo '<span class="notice">';
00280         echo _("Erreur")." ".$e->getMessage();
00281         echo '</span>';
00282         $sub_action="add_action";
00283         $error_id=$e->getCode();
00284     }
00285 }
00286 //--------------------------------------------------------------------------------
00287 // Add an action
00288 if ($sub_action == "add_action")
00289 {
00290         $act = new Follow_Up($cn);
00291         $act->fromArray($_POST);
00292         $act->ag_id = 0;
00293         $act->d_id = 0;
00294         echo '<div class="content">';
00295         // Add hidden tag
00296         echo '<form method="post" action="do.php" name="form_add" id="form_add" enctype="multipart/form-data" >';
00297         echo $supl_hidden;
00298         echo dossier::hidden();
00299 
00300 
00301         $act->ag_comment = (isset($_POST['ag_comment'])) ? Decode($_POST['ag_comment']) : "";
00302         if (isset($_REQUEST['qcode']))
00303                 $act->qcode_dest = $_REQUEST['qcode'];
00304         echo $act->Display('NEW', false, $base, $retour);
00305 
00306         echo '<input type="hidden" name="ac" value="' . $_REQUEST["ac"] . '">';
00307         echo '<input type="hidden" name="sa" value="save_action_st2">';
00308         echo '<input type="hidden" name="save_action_st2" value="save_action_st2">';
00309         echo '<input type="submit" class="button" name="save_action_st2" value="' . _('Enregistrer') . '">';
00310         echo '</form>';
00311 
00312         echo '</div>';
00313   
00314 }
00315 if ( $error_id != 0 ){
00316             $error[10]='dt_id';
00317             $error[20]='ag_timestamp';
00318             $error[30]='ag_remind_date';
00319             $div=$error[$error_id];
00320             $js=<<<EOF
00321     <script>$('$div').style.borderColor="red";
00322    $('info_div').innerHTML='erreur';     
00323    </script>
00324                     
00325 EOF;
00326             echo $js;
00327         }
00328 ?>
00329 
 All Data Structures Namespaces Files Functions Variables Enumerations