Esempio n. 1
0
/**
 * 	Cree une propale sur disque en fonction du modele de PROPALE_ADDON_PDF
 * 	@param	    db  			Database handler
 * 	@param	    object			Object proposal
 * 	@param	    modele			Force model to use ('' to not force)
 * 	@param		outputlangs		Object langs to use for output
 *  @param      hidedetails     Hide details of lines
 *  @param      hidedesc        Hide description
 *  @param      hideref         Hide ref
 * 	@return     int         	0 if KO, 1 if OK
 */
function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
    global $conf, $user, $langs;
    $langs->load("propale");
    $dir = "/includes/modules/propale/";
    $srctemplatepath = '';
    $modelisok = 0;
    // Positionne le modele sur le nom du modele a utiliser
    if (!dol_strlen($modele)) {
        if (!empty($conf->global->PROPALE_ADDON_PDF)) {
            $modele = $conf->global->PROPALE_ADDON_PDF;
        } else {
            $modele = 'azur';
        }
    }
    // Positionne modele sur le nom du modele de propale a utiliser
    $file = "pdf_propale_" . $modele . ".modules.php";
    // On verifie l'emplacement du modele
    $file = dol_buildpath($dir . $file);
    if ($modele && file_exists($file)) {
        $modelisok = 1;
    }
    // Si model pas encore bon
    if (!$modelisok) {
        if ($conf->global->PROPALE_ADDON_PDF) {
            $modele = $conf->global->PROPALE_ADDON_PDF;
        }
        $file = "pdf_propale_" . $modele . ".modules.php";
        // On verifie l'emplacement du modele
        $file = dol_buildpath($dir . $file);
        if (file_exists($file)) {
            $modelisok = 1;
        }
    }
    // Si model pas encore bon
    if (!$modelisok && is_array($liste)) {
        $liste = array();
        $model = new ModelePDFPropales();
        $liste = $model->liste_modeles($db);
        $modele = key($liste);
        // Renvoie premiere valeur de cle trouve dans le tableau
        $file = "pdf_propale_" . $modele . ".modules.php";
        $file = dol_buildpath($dir . $file);
        if (file_exists($file)) {
            $modelisok = 1;
        }
    }
    // Charge le modele
    if ($modelisok) {
        $classname = "pdf_propale_" . $modele;
        require_once $file;
        $obj = new $classname($db);
        // We save charset_output to restore it because write_file can change it if needed for
        // output format that does not support UTF8.
        $sav_charset_output = $outputlangs->charset_output;
        if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0) {
            $outputlangs->charset_output = $sav_charset_output;
            // on supprime l'image correspondant au preview
            propale_delete_preview($db, $object->id);
            // Appel des triggers
            include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
            $interface = new Interfaces($db);
            $result = $interface->run_triggers('PROPAL_BUILDDOC', $object, $user, $langs, $conf);
            if ($result < 0) {
                $error++;
                $this->errors = $interface->errors;
            }
            // Fin appel triggers
            return 1;
        } else {
            $outputlangs->charset_output = $sav_charset_output;
            dol_syslog("modules_propale::propale_pdf_create error");
            dol_print_error($db, $obj->error);
            return 0;
        }
    } else {
        if (!$conf->global->PROPALE_ADDON_PDF) {
            print $langs->trans("Error") . " " . $langs->trans("Error_PROPALE_ADDON_PDF_NotDefined");
        } else {
            print $langs->trans("Error") . " " . $langs->trans("ErrorFileDoesNotExists", $file);
        }
        return 0;
    }
}
Esempio n. 2
0
 /**
  *    \brief      Efface propal
  *    \param      user        Objet du user qui efface
  */
 function delete($user, $notrigger = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
     $error = 0;
     $this->db->begin();
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE fk_propal = " . $this->id;
     if ($this->db->query($sql)) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propal WHERE rowid = " . $this->id;
         if ($this->db->query($sql)) {
             // Delete linked contacts
             $res = $this->delete_linked_contact();
             if ($res < 0) {
                 $this->error = 'ErrorFailToDeleteLinkedContact';
                 $this->db->rollback();
                 return 0;
             }
             // We remove directory
             $propalref = dol_sanitizeFileName($this->ref);
             if ($conf->propale->dir_output) {
                 $dir = $conf->propale->dir_output . "/" . $propalref;
                 $file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
                 if (file_exists($file)) {
                     propale_delete_preview($this->db, $this->id, $this->ref);
                     if (!dol_delete_file($file)) {
                         $this->error = 'ErrorFailToDeleteFile';
                         $this->db->rollback();
                         return 0;
                     }
                 }
                 if (file_exists($dir)) {
                     $res = @dol_delete_dir($dir);
                     if (!$res) {
                         $this->error = 'ErrorFailToDeleteDir';
                         $this->db->rollback();
                         return 0;
                     }
                 }
             }
             if (!$notrigger) {
                 // Call triggers
                 include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
                 $interface = new Interfaces($this->db);
                 $result = $interface->run_triggers('PROPAL_DELETE', $this, $user, $langs, $conf);
                 if ($result < 0) {
                     $error++;
                     $this->errors = $interface->errors;
                 }
                 // End call triggers
             }
             if (!$error) {
                 dol_syslog("Suppression de la proposition {$this->id} par {$user->id}", LOG_DEBUG);
                 $this->db->commit();
                 return 1;
             } else {
                 $this->db->rollback();
                 return 0;
             }
         } else {
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->db->rollback();
         return -1;
     }
 }