Permalink
Browse files

Fix: problem with external modules and uniformize code

  • Loading branch information...
1 parent 85e7e5e commit b51cd362b018d2091e533bf93e372e608f670e46 Regis Houssin committed Jun 9, 2012
@@ -34,10 +34,10 @@
$langs->load('compta');
$langs->load('other');
-$action = GETPOST('action');
-$confirm = GETPOST('confirm');
+$action = GETPOST('action','alpha');
+$confirm = GETPOST('confirm','alpha');
$id = GETPOST('id','int');
-$ref = GETPOST('ref');
+$ref = GETPOST('ref','alpha');
$mesg='';
if (isset($_SESSION['DolMessage']))
@@ -66,6 +66,11 @@
if (! $sortfield) $sortfield="name";
$object = new Propal($db);
+$object->fetch($id,$ref);
+if ($object->id > 0)
+{
+ $object->fetch_thirdparty();
+}
/*
* Actions
@@ -74,7 +79,7 @@
// Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if ($object->fetch($id))
+ if ($object->id > 0)
{
$object->fetch_thirdparty();
@@ -119,10 +124,9 @@
// Delete
if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
- if ($object->fetch($id))
+ if ($object->id > 0)
{
$langs->load("other");
- $object->fetch_thirdparty();
$upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
@@ -142,83 +146,73 @@
$form = new Form($db);
-if ($id > 0 || ! empty($ref))
+if ($object->id > 0)
{
- if ($object->fetch($id,$ref))
- {
- $object->fetch_thirdparty();
-
- $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref);
-
- $head = propal_prepare_head($object);
- dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
-
-
- // Construit liste des fichiers
- $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
- $totalsize=0;
- foreach($filearray as $key => $file)
- {
- $totalsize+=$file['size'];
- }
-
-
- print '<table class="border"width="100%">';
-
- $linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder".'">'.$langs->trans("BackToList").'</a>';
-
- // Ref
- print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
- print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
- print '</td></tr>';
-
- // Ref client
- print '<tr><td>';
- print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
- print $langs->trans('RefCustomer').'</td><td align="left">';
- print '</td>';
- print '</tr></table>';
- print '</td><td colspan="3">';
- print $object->ref_client;
- print '</td>';
- print '</tr>';
-
- // Customer
- print "<tr><td>".$langs->trans("Company")."</td>";
- print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
-
- print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
- print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
-
- print '</table>';
-
- print '</div>';
-
- dol_htmloutput_mesg($mesg,$mesgs);
-
- /*
- * Confirmation suppression fichier
- */
- if ($action == 'delete')
- {
- $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
- if ($ret == 'html') print '<br>';
- }
-
- // Affiche formulaire upload
- $formfile=new FormFile($db);
- $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id,'',0,0,$user->rights->propale->creer,50,$object);
-
-
- // List of document
- $param='&id='.$object->id;
- $formfile->list_of_documents($filearray,$object,'propal',$param);
-
- }
- else
- {
- dol_print_error($db);
- }
+ $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref);
+
+ $head = propal_prepare_head($object);
+ dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
+
+
+ // Construit liste des fichiers
+ $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+ $totalsize=0;
+ foreach($filearray as $key => $file)
+ {
+ $totalsize+=$file['size'];
+ }
+
+
+ print '<table class="border"width="100%">';
+
+ $linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder".'">'.$langs->trans("BackToList").'</a>';
+
+ // Ref
+ print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
+ print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
+ print '</td></tr>';
+
+ // Ref client
+ print '<tr><td>';
+ print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
+ print $langs->trans('RefCustomer').'</td><td align="left">';
+ print '</td>';
+ print '</tr></table>';
+ print '</td><td colspan="3">';
+ print $object->ref_client;
+ print '</td>';
+ print '</tr>';
+
+ // Customer
+ print "<tr><td>".$langs->trans("Company")."</td>";
+ print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
+
+ print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
+ print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
+
+ print '</table>';
+
+ print '</div>';
+
+ dol_htmloutput_mesg($mesg,$mesgs);
+
+ /*
+ * Confirmation suppression fichier
+ */
+ if ($action == 'delete')
+ {
+ $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
+ if ($ret == 'html') print '<br>';
+ }
+
+ // Affiche formulaire upload
+ $formfile=new FormFile($db);
+ $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id,'',0,0,$user->rights->propale->creer,50,$object);
+
+
+ // List of document
+ $param='&id='.$object->id;
+ $formfile->list_of_documents($filearray,$object,'propal',$param);
}
else
{
@@ -792,16 +792,40 @@ function delete($user,$langs='',$conf='')
$error++;
}
}
+
+ if (! $error)
+ {
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('CONTRACT_DELETE',$this,$user,$langs,$conf);
+ if ($result < 0) {
+ $error++; $this->errors=$interface->errors;
+ }
+ // Fin appel triggers
+ }
+
+ if (! $error)
+ {
+ // We remove directory
+ $ref = dol_sanitizeFileName($this->ref);
+ if ($conf->contrat->dir_output)
+ {
+ $dir = $conf->contrat->dir_output . "/" . $ref;
+ if (file_exists($dir))
+ {
+ $res=@dol_delete_dir_recursive($dir);
+ if (! $res)
+ {
+ $this->error='ErrorFailToDeleteDir';
+ $error++;
+ }
+ }
+ }
+ }
if (! $error)
{
- // Appel des triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('CONTRACT_DELETE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
-
$this->db->commit();
return 1;
}
@@ -35,8 +35,18 @@
$langs->load("other");
$langs->load("products");
-if (!$user->rights->contrat->lire)
- accessforbidden();
+
+$action = GETPOST('action','alpha');
+$confirm = GETPOST('confirm','alpha');
+$id = GETPOST('id','int');
+$ref = GETPOST('ref','alpha');
+
+$mesg='';
+if (isset($_SESSION['DolMessage']))
+{
+ $mesg=$_SESSION['DolMessage'];
+ unset($_SESSION['DolMessage']);
+}
// Security check
if ($user->societe_id > 0)
@@ -45,6 +55,7 @@
$action='';
$socid = $user->societe_id;
}
+$result = restrictedArea($user, 'contrat', $id);
// Get parameters
$sortfield = GETPOST("sortfield",'alpha');
@@ -58,10 +69,14 @@
if (! $sortfield) $sortfield="name";
-$contrat = new Contrat($db);
-$contrat->fetch($_GET["id"]);
+$object = new Contrat($db);
+$object->fetch($id, $ref);
+if ($object->id > 0)
+{
+ $object->fetch_thirdparty();
+}
-$upload_dir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($contrat->ref);
+$upload_dir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($object->ref);
$modulepart='contract';
@@ -105,6 +120,21 @@
}
}
+// Delete
+if ($action == 'confirm_deletefile' && $confirm == 'yes')
+{
+ if ($object->id)
+ {
+ $langs->load("other");
+
+ $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
+ $ret=dol_delete_file($file,0,0,0,$object);
+ $_SESSION['DolMessage'] = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'</div>';
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+ exit;
+ }
+}
+
/*
*
@@ -115,24 +145,9 @@
llxHeader("","",$langs->trans("CardProduct".$product->type));
-if ($contrat->id)
+if ($object->id)
{
- $soc = new Societe($db);
- $soc->fetch($contrat->societe->id);
-
- if ( $error_msg )
- {
- echo '<div class="error">'.$error_msg.'</div><br>';
- }
-
- if ($_GET["action"] == 'delete')
- {
- $file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
- $result=dol_delete_file($file);
- //if ($result >= 0) $mesg=$langs->trans("FileWasRemoced");
- }
-
- $head=contract_prepare_head($contrat, $user);
+ $head=contract_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("Contract"), 0, 'contract');
@@ -149,27 +164,38 @@
print '<table class="border" width="100%">';
// Reference
- print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$contrat->ref.'</td></tr>';
+ print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$object->ref.'</td></tr>';
// Societe
print '<tr><td>'.$langs->trans("Customer").'</td>';
- print '<td colspan="3">'.$soc->getNomUrl(1).'</td></tr>';
+ print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
+
+ dol_htmloutput_mesg($mesg,$mesgs);
+
+ /*
+ * Confirmation suppression fichier
+ */
+ if ($action == 'delete')
+ {
+ $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
+ if ($ret == 'html') print '<br>';
+ }
// Affiche formulaire upload
$formfile=new FormFile($db);
- $formfile->form_attach_new_file(DOL_URL_ROOT.'/contrat/document.php?id='.$contrat->id,'',0,0,$user->rights->contrat->creer,50,$object);
+ $formfile->form_attach_new_file(DOL_URL_ROOT.'/contrat/document.php?id='.$object->id,'',0,0,$user->rights->contrat->creer,50,$object);
// List of document
- $param='&id='.$contrat->id;
- $formfile->list_of_documents($filearray,$contrat,'contract',$param);
+ $param='&id='.$object->id;
+ $formfile->list_of_documents($filearray,$object,'contract',$param);
}
else
@@ -427,7 +427,8 @@
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)
{
- $object->fetch($id);
+ $object->fetch($id);
+ $object->fetch_thirdparty();
$result=$object->delete($user,$langs,$conf);
if ($result >= 0)
{
Oops, something went wrong.

0 comments on commit b51cd36

Please sign in to comment.