/**
   *    \brief  Insere le produit en base
   *    \param  user utilisateur qui effectue l'insertion
   */

  function create($user)
    {
      if (dol_strlen(trim($this->numero)) && dol_strlen(trim($this->intitule)))
	{
	  $sql = "SELECT count(*)";
	  $sql .= " FROM ".MAIN_DB_PREFIX."compta_compte_generaux ";
	  $sql .= " WHERE numero = '" .trim($this->numero)."'";

	  $resql = $this->db->query($sql) ;

	  if ( $resql )
	    {
	      $row = $this->db->fetch_array($resql);
	      if ($row[0] == 0)
		{
		  $sql = "INSERT INTO ".MAIN_DB_PREFIX."compta_compte_generaux (date_creation, fk_user_author, numero,intitule)";
		  $sql .= " VALUES (".$this->db->idate(mktime()).",".$user->id.",'".$this->numero."','".$this->intitule."')";

		  $resql = $this->db->query($sql);
		  if ( $resql )
		    {
		      $id = $this->db->last_insert_id(MAIN_DB_PREFIX."compta_compte_generaux");

		      if ($id > 0)
			{
			  $this->id = $id;
			  $result = 0;
			}
		      else
			{
			  $result = -2;
			  dol_syslog("ComptaCompte::Create Erreur $result lecture ID");
			}
		    }
		  else
		    {
		      $result = -1;
		      dol_syslog("ComptaCompte::Create Erreur $result INSERT Mysql");
		    }
		}
	      else
		{
		  $result = -3;
		  dol_syslog("ComptaCompte::Create Erreur $result SELECT Mysql");
		}
	    }
	  else
	    {
	      $result = -5;
	      dol_syslog("ComptaCompte::Create Erreur $result SELECT Mysql");
	    }
	}
      else
	{
	  $result = -4;
	  dol_syslog("ComptaCompte::Create Erreur  $result Valeur Manquante");
	}

      return $result;
    }
Example #2
0
	/**
	 *  \brief      Return geo coordinates of an address
	 *  \param      address		Address
	 * 							Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France
	 *							Example: 188, rue de Fontenay,+94300,+Vincennes,+France
	 *	\return		string		Coordinates
	 */
	function getGeoCoordinatesOfAddress($address)
	{
		global $conf;


		$i=0;

		// Desired address
		$urladdress = "http://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key;

		// Retrieve the URL contents
		$page = file_get_contents($urladdress);

		$code = strstr($page, '<coordinates>');
		$code = strstr($code, '>');
		$val=strpos($code, "<");
		$code = substr($code, 1, $val-1);
		//print $code;
		//print "<br>";
		$latitude = substr($code, 0, strpos($code, ","));
		$longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3);

		// Output the coordinates
		//echo "Longitude: $longitude ',' Latitude: $latitude";

		$i++;
	}
Example #3
0
 /**
  * Load data into info_box_contents array to show array later.
  *
  * @param int $max of records to load
  *
  * @return void
  */
 public function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     dol_include_once('/lead/class/lead.class.php');
     $lead = new Lead($db);
     $lead->fetch_all('DESC', 't.date_closure', $max, 0, array('t.date_closure<' => dol_now()));
     $text = $langs->trans("LeadLate", $max);
     $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text));
     $i = 0;
     foreach ($lead->lines as $line) {
         // FIXME: line is an array, not an object
         $line->fetch_thirdparty();
         // Ref
         $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => dol_buildpath('/lead/lead/card.php', 1) . '?id=' . $line->id);
         $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $line->ref, 'url' => dol_buildpath('/lead/lead/card.php', 1) . '?id=' . $line->id);
         $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $line->fk_soc);
         $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($line->thirdparty->name, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $line->fk_soc);
         // Amount Guess
         $this->info_box_contents[$i][4] = array('td' => 'align="left"', 'text' => price($line->amount_prosp, 'HTML') . $langs->getCurrencySymbol($conf->currency));
         // Amount real
         $this->info_box_contents[$i][5] = array('td' => 'align="left"', 'text' => $line->getRealAmount() . $langs->getCurrencySymbol($conf->currency));
         $i++;
     }
 }
Example #4
0
 /**
  * Load data into info_box_contents array to show array later.
  *
  * 	@param		int		$max		Maximum number of records to load
  * 	@return		void
  */
 public function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     //include_once DOL_DOCUMENT_ROOT . "/mymodule/class/mymodule.class.php";
     $text = $langs->trans("MyBoxDescription", $max);
     $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text));
     $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("MyBoxContent"));
 }
Example #5
0
 /**
  *  Load data for box to show them later
  *
  *  @param   int		$max        Maximum number of records to load
  *  @return  void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     $totalMnt = 0;
     $totalnb = 0;
     $totalnbTask = 0;
     $textHead = $langs->trans("Projects");
     $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
     // list the summary of the orders
     if ($user->rights->projet->lire) {
         $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut ";
         $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
         $sql .= " WHERE p.entity = " . $conf->entity;
         $sql .= " AND p.fk_statut = 1";
         // Seulement les projets ouverts
         $sql .= " ORDER BY p.datec DESC";
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $i = 0;
             while ($i < $num) {
                 $objp = $db->fetch_object($result);
                 $tooltip = $langs->trans('Project') . ': ' . $objp->ref;
                 $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => 'object_project', 'tooltip' => $tooltip, 'url' => DOL_URL_ROOT . "/projet/card.php?id=" . $objp->rowid);
                 $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref, 'tooltip' => $tooltip, 'url' => DOL_URL_ROOT . "/projet/card.php?id=" . $objp->rowid);
                 $this->info_box_contents[$i][2] = array('td' => 'align="left"', 'text' => $objp->title);
                 $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
                 $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as pt on pt.fk_projet = p.rowid";
                 $sql .= " WHERE p.entity = " . $conf->entity;
                 $sql .= " AND p.rowid = " . $objp->rowid;
                 $resultTask = $db->query($sql);
                 if ($resultTask) {
                     $objTask = $db->fetch_object($resultTask);
                     $this->info_box_contents[$i][3] = array('td' => 'align="right"', 'text' => number_format($objTask->nb, 0, ',', ' ') . "&nbsp;" . $langs->trans("Tasks"));
                     if ($objTask->nb > 0) {
                         $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => number_format($objTask->totprogress / $objTask->nb, 0, ',', ' ') . "%");
                     } else {
                         $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => "N/A&nbsp;");
                     }
                     $totalnbTask += $objTask->nb;
                 } else {
                     $this->info_box_contents[$i][3] = array('td' => 'align="right"', 'text' => number_format(0, 0, ',', ' '));
                     $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => "N/A&nbsp;");
                 }
                 $i++;
             }
         }
     }
     // Add the sum à the bottom of the boxes
     $this->info_box_contents[$i][0] = array('tr' => 'class="liste_total"', 'td' => 'align="left" ', 'text' => "&nbsp;");
     $this->info_box_contents[$i][1] = array('td' => '', 'text' => $langs->trans("Total") . "&nbsp;" . $textHead, 'text' => "&nbsp;");
     $this->info_box_contents[$i][2] = array('td' => 'align="right" ', 'text' => number_format($num, 0, ',', ' ') . "&nbsp;" . $langs->trans("Projects"));
     $this->info_box_contents[$i][3] = array('td' => 'align="right" ', 'text' => number_format($totalnbTask, 0, ',', ' ') . "&nbsp;" . $langs->trans("Tasks"));
     $this->info_box_contents[$i][4] = array('td' => '', 'text' => "&nbsp;");
 }
/**
 *		Create object on disk
 *		@param	    db  			objet base de donnee
 *		@param	    object			object supplier invoice
 *		@param	    model			force le modele a utiliser ('' to not force)
 *		@param		outputlangs		objet lang a utiliser pour traduction
 *      @return     int         	0 si KO, 1 si OK
 */
function supplier_invoice_pdf_create($db, $object, $model, $outputlangs)
{
	global $conf, $langs;

	$langs->load("suppliers");

	$dir = DOL_DOCUMENT_ROOT."/includes/modules/supplier_invoice/pdf/";

	// Positionne modele sur le nom du modele de invoice fournisseur a utiliser
	if (! dol_strlen($model))
	{
		if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
		{
			$model = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
		}
		else
		{
		    $model = 'canelle';
			//print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined");
			//return 0;
		}
	}
	// Charge le modele
	$file = "pdf_".$model.".modules.php";
	if (file_exists($dir.$file))
	{
		$classname = "pdf_".$model;
		require_once($dir.$file);

		$obj = new $classname($db,$object);

		// 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) > 0)
		{
			// on supprime l'image correspondant au preview
			supplier_invoice_delete_preview($db, $object->id);

			$outputlangs->charset_output=$sav_charset_output;
			return 1;
		}
		else
		{
			$outputlangs->charset_output=$sav_charset_output;
			dol_syslog("Erreur dans supplier_invoice_pdf_create");
			dol_print_error($db,$obj->error);
			return 0;
		}
	}
	else
	{
		print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
		return 0;
	}
}
Example #7
0
/**
 *	\brief   	Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF
 *	\param   	db  			objet base de donnee
 *	\param   	id				id de la facture a creer
 *	\param	    message			message
 *	\param	    modele			force le modele a utiliser ('' to not force)
 *	\param		outputlangs		objet lang a utiliser pour traduction
 *	\return  	int        		<0 if KO, >0 if OK
 */
function members_label_pdf_create($db, $arrayofmembers, $modele, $outputlangs)
{
	global $conf,$langs;
	$langs->load("members");

	$dir = DOL_DOCUMENT_ROOT . "/includes/modules/member/labels/";

	// Positionne modele sur le nom du modele a utiliser
	if (! dol_strlen($modele))
	{
		if ($conf->global->ADHERENT_ETIQUETTE_TYPE)
		{
			$modele = $conf->global->ADHERENT_ETIQUETTE_TYPE;
			$code = $conf->global->ADHERENT_ETIQUETTE_TYPE;
		}
		else
		{
		    $modele = 'L7163';
		    $code = 'L7163';
		}
	}
    $modele='standardlabel';

	// Charge le modele
	$file = "pdf_".$modele.".class.php";
	if (file_exists($dir.$file))
	{
		$classname = "pdf_".$modele;
		require_once($dir.$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($arrayofmembers, $outputlangs) > 0)
		{
			$outputlangs->charset_output=$sav_charset_output;
			return 1;
		}
		else
		{
			$outputlangs->charset_output=$sav_charset_output;
			dol_print_error($db,"members_card_pdf_create Error: ".$obj->error);
			return -1;
		}
	}

	else
	{
		dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file));
		return -1;
	}


}
Example #8
0
/**
 *	Decode a base 64 encoded + specific string.
 *  This function is called by filefunc.inc.php at each page call.
 *	Code of this function is useless and we should use base64_decode only instead
 *
 *	@param   string		$chain		string to decode
 *	@return  string					decoded string
 */
function dol_decode($chain)
{
    $chain = base64_decode($chain);
    $strlength = dol_strlen($chain);
    for ($i = 0; $i < $strlength; $i++) {
        $output_tab[$i] = chr(ord(substr($chain, $i, 1)) - 17);
    }
    $string_decoded = implode("", $output_tab);
    return $string_decoded;
}
/**
 *	\brief   	Cree un bordereau remise de cheque
 *	\param   	db  			objet base de donnee
 *	\param   	id				Object invoice (or id of invoice)
 *	\param	    message			message
 *	\param	    modele			force le modele a utiliser ('' to not force)
 *	\param		outputlangs		objet lang a utiliser pour traduction
 *	\return  	int        		<0 if KO, >0 if OK
 * 	TODO
 */
function chequereceipt_pdf_create($db, $id, $message, $modele, $outputlangs)
{
	global $conf,$langs;
	$langs->load("bills");

	$dir = DOL_DOCUMENT_ROOT . "/includes/modules/cheque/pdf/";

	// Positionne modele sur le nom du modele a utiliser
	if (! dol_strlen($modele))
	{
		if ($conf->global->FACTURE_ADDON_PDF)
		{
			$modele = $conf->global->FACTURE_ADDON_PDF;
		}
		else
		{
			//print $langs->trans("Error")." ".$langs->trans("Error_FACTURE_ADDON_PDF_NotDefined");
			//return 0;
			$modele = 'crabe';
		}
	}

	// Charge le modele
	$file = "pdf_".$modele.".modules.php";
	if (file_exists($dir.$file))
	{
		$classname = "pdf_".$modele;
		require_once($dir.$file);

		$obj = new $classname($db);
		$obj->message = $message;

		// 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($id, $outputlangs) > 0)
		{
			$outputlangs->charset_output=$sav_charset_output;
			return 1;
		}
		else
		{
			$outputlangs->charset_output=$sav_charset_output;
			dol_print_error($db,"facture_pdf_create Error: ".$obj->error);
			return -1;
		}

	}
	else
	{
		dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file));
		return -1;
	}
}
 /**
  * Encrypt en create the cookie
  *
  * @return	void
  */
 function cryptCookie()
 {
     if (!empty($this->myKey)) {
         $valuecrypt = base64_encode($this->myValue);
         $max = dol_strlen($valuecrypt) - 1;
         for ($f = 0; $f <= $max; $f++) {
             $this->cookie .= intval(ord($valuecrypt[$f])) * $this->myKey . "|";
         }
     } else {
         $this->cookie = $this->myValue;
     }
     setcookie($this->myCookie, $this->cookie, $this->myExpire, $this->myPath, $this->myDomain, $this->mySecure);
 }
Example #11
0
/**
 *
 */
function make_alpha_from_numbers($number)
{
	$numeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if($number<dol_strlen($numeric))
	{
		return $numeric[$number];
	}
	else
	{
		$dev_by = floor($number/dol_strlen($numeric));
		return "" . make_alpha_from_numbers($dev_by-1) . make_alpha_from_numbers($number-($dev_by*dol_strlen($numeric)));
	}
}
Example #12
0
 /**
  *  Load data for box to show them later
  *
  *  @param  int     $max        Maximum number of records to load
  *  @return void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     $totalMnt = 0;
     $totalnb = 0;
     $totalDuree = 0;
     include_once DOL_DOCUMENT_ROOT . "/projet/class/task.class.php";
     $taskstatic = new Task($db);
     $textHead = $langs->trans("Tasks") . "&nbsp;" . date("Y");
     $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
     // list the summary of the orders
     if ($user->rights->projet->lire) {
         // FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
         $sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
         $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task as pt, " . MAIN_DB_PREFIX . "projet_task_time as ptt";
         $sql .= " WHERE pt.datec BETWEEN '" . $this->db->idate(dol_get_first_day(date("Y"), 1)) . "' AND '" . $this->db->idate(dol_get_last_day(date("Y"), 12)) . "'";
         $sql .= " AND pt.rowid = ptt.fk_task";
         $sql .= " GROUP BY pt.fk_statut ";
         $sql .= " ORDER BY pt.fk_statut DESC";
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $i = 0;
             while ($i < $num) {
                 $objp = $db->fetch_object($result);
                 $this->info_box_contents[$i][] = array('td' => 'align="left"', 'text' => $langs->trans("Task") . " " . $taskstatic->LibStatut($objp->fk_statut, 0));
                 $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => $objp->nb . "&nbsp;" . $langs->trans("Tasks"), 'url' => DOL_URL_ROOT . "/projet/tasks/list.php?leftmenu=projects&viewstatut=" . $objp->fk_statut);
                 $totalnb += $objp->nb;
                 $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->plannedtot, 'all', 25200, 5));
                 $totalplannedtot += $objp->plannedtot;
                 $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->durationtot, 'all', 25200, 5));
                 $totaldurationtot += $objp->durationtot;
                 $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut, 3));
                 $i++;
             }
         } else {
             dol_print_error($this->db);
         }
     }
     // Add the sum à the bottom of the boxes
     $this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => 'align="left"', 'text' => $langs->trans("Total") . "&nbsp;" . $textHead);
     $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ') . "&nbsp;" . $langs->trans("Tasks"));
     $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot, 'all', 25200, 5));
     $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot, 'all', 25200, 5));
     $this->info_box_contents[$i][] = array('td' => '', 'text' => "");
 }
Example #13
0
 /**
  *  Load data for box to show them later
  *
  *  @param  int     $max        Maximum number of records to load
  *  @return void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     $totalMnt = 0;
     $totalnb = 0;
     $totalDuree = 0;
     include_once DOL_DOCUMENT_ROOT . "/projet/class/task.class.php";
     $taskstatic = new Task($db);
     $textHead = $langs->trans("Tasks") . "&nbsp;" . date("Y");
     $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
     // list the summary of the orders
     if ($user->rights->projet->lire) {
         $sql = "SELECT pt.fk_statut, count(pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
         $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task as pt, " . MAIN_DB_PREFIX . "projet_task_time as ptt";
         $sql .= " WHERE DATE_FORMAT(pt.datec,'%Y') = '" . date("Y") . "' ";
         $sql .= " AND pt.rowid = ptt.fk_task";
         $sql .= " GROUP BY pt.fk_statut ";
         $sql .= " ORDER BY pt.fk_statut DESC";
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $i = 0;
             while ($i < $num) {
                 $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => 'object_projecttask');
                 $objp = $db->fetch_object($result);
                 $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $langs->trans("Task") . "&nbsp;" . $taskstatic->LibStatut($objp->fk_statut, 0));
                 $this->info_box_contents[$i][2] = array('td' => 'align="right"', 'text' => $objp->nb . "&nbsp;" . $langs->trans("Tasks"), 'url' => DOL_URL_ROOT . "/projet/tasks/index.php?leftmenu=projects&viewstatut=" . $objp->fk_statut);
                 $totalnb += $objp->nb;
                 $this->info_box_contents[$i][3] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->plannedtot, 'all', 25200, 5));
                 $totalplannedtot += $objp->plannedtot;
                 $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->durationtot, 'all', 25200, 5));
                 $totaldurationtot += $objp->durationtot;
                 $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut, 3));
                 $i++;
             }
         }
     }
     // Add the sum à the bottom of the boxes
     $this->info_box_contents[$i][0] = array('tr' => 'class="liste_total"', 'td' => 'align="left"', 'text' => $langs->trans("Total") . "&nbsp;" . $textHead);
     $this->info_box_contents[$i][1] = array('td' => '', 'text' => "");
     $this->info_box_contents[$i][2] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ') . "&nbsp;" . $langs->trans("Tasks"));
     $this->info_box_contents[$i][3] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot, 'all', 25200, 5));
     $this->info_box_contents[$i][4] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot, 'all', 25200, 5));
     $this->info_box_contents[$i][5] = array('td' => '', 'text' => "");
 }
Example #14
0
 if ($sref) {
     $sql .= natural_search('p.ref', $sref);
 }
 if ($snom) {
     $sql .= natural_search('p.label', $snom);
 }
 if ($sbarcode) {
     $sql .= natural_search('p.barcode', $sbarcode);
 }
 if (isset($tosell) && dol_strlen($tosell) > 0 && $tosell != -1) {
     $sql .= " AND p.tosell = " . $db->escape($tosell);
 }
 if (isset($tobuy) && dol_strlen($tobuy) > 0 && $tobuy != -1) {
     $sql .= " AND p.tobuy = " . $db->escape($tobuy);
 }
 if (dol_strlen($canvas) > 0) {
     $sql .= " AND p.canvas = '" . $db->escape($canvas) . "'";
 }
 if ($catid > 0) {
     $sql .= " AND cp.fk_categorie = " . $catid;
 }
 if ($catid == -2) {
     $sql .= " AND cp.fk_categorie IS NULL";
 }
 if ($search_categ > 0) {
     $sql .= " AND cp.fk_categorie = " . $db->escape($search_categ);
 }
 if ($search_categ == -2) {
     $sql .= " AND cp.fk_categorie IS NULL";
 }
 if ($fourn_id > 0) {
Example #15
0
			{
				$filelist[]=$file;
			}
			else if (preg_match('/'.$to.'/i',$file))	// First test may be false if we migrate from x.y.* to x.y.*
			{
				$filelist[]=$file;
			}
		}

		# Boucle sur chaque fichier
		foreach($filelist as $file)
		{
			print '<tr><td nowrap>';
			print $langs->trans("ChoosedMigrateScript").'</td><td align="right">'.$file.'</td></tr>'."\n";

			$name = substr($file, 0, dol_strlen($file) - 4);

			// Run sql script
			$ok=run_sql($dir.$file, 0, '', 1);
		}
	}

	print '</table>';

	if ($db->connected) $db->close();
}


if (empty($actiondone))
{
    print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
 /**
  * Adds access rights
  *
  * @param   int $reinitadminperms   If 1, we also grant them to all admin users
  * @param   int $force_entity       Force current entity
  *
  * @return  int                     Error count (0 if OK)
  */
 function insert_permissions($reinitadminperms = 0, $force_entity = null)
 {
     global $conf, $user;
     $err = 0;
     $entity = !empty($force_entity) ? $force_entity : $conf->entity;
     // Test if module is activated
     $sql_del = "SELECT " . $this->db->decrypt('value') . " as value";
     $sql_del .= " FROM " . MAIN_DB_PREFIX . "const";
     $sql_del .= " WHERE " . $this->db->decrypt('name') . " = '" . $this->const_name . "'";
     $sql_del .= " AND entity IN (0," . $entity . ")";
     dol_syslog(get_class($this) . "::insert_permissions", LOG_DEBUG);
     $resql = $this->db->query($sql_del);
     if ($resql) {
         $obj = $this->db->fetch_object($resql);
         if ($obj !== null && !empty($obj->value) && !empty($this->rights)) {
             // If the module is active
             foreach ($this->rights as $key => $value) {
                 $r_id = $this->rights[$key][0];
                 $r_desc = $this->rights[$key][1];
                 $r_type = isset($this->rights[$key][2]) ? $this->rights[$key][2] : '';
                 $r_def = $this->rights[$key][3];
                 $r_perms = $this->rights[$key][4];
                 $r_subperms = isset($this->rights[$key][5]) ? $this->rights[$key][5] : '';
                 $r_modul = $this->rights_class;
                 if (empty($r_type)) {
                     $r_type = 'w';
                 }
                 // Search if perm already present
                 $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "rights_def";
                 $sql .= " WHERE id = " . $r_id . " AND entity = " . $entity;
                 $resqlselect = $this->db->query($sql);
                 $obj = $this->db->fetch_object($resqlselect);
                 if ($obj->nb == 0) {
                     if (dol_strlen($r_perms)) {
                         if (dol_strlen($r_subperms)) {
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def";
                             $sql .= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
                             $sql .= " VALUES ";
                             $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ",'" . $r_perms . "','" . $r_subperms . "')";
                         } else {
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def";
                             $sql .= " (id, entity, libelle, module, type, bydefault, perms)";
                             $sql .= " VALUES ";
                             $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ",'" . $r_perms . "')";
                         }
                     } else {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def ";
                         $sql .= " (id, entity, libelle, module, type, bydefault)";
                         $sql .= " VALUES ";
                         $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ")";
                     }
                     $resqlinsert = $this->db->query($sql, 1);
                     if (!$resqlinsert) {
                         if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") {
                             $this->error = $this->db->lasterror();
                             $err++;
                             break;
                         } else {
                             dol_syslog(get_class($this) . "::insert_permissions record already exists", LOG_INFO);
                         }
                     }
                     $this->db->free($resqlinsert);
                 }
                 $this->db->free($resqlselect);
                 // If we want to init permissions on admin users
                 if ($reinitadminperms) {
                     if (!class_exists('User')) {
                         require DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
                     }
                     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "user WHERE admin = 1";
                     dol_syslog(get_class($this) . "::insert_permissions Search all admin users", LOG_DEBUG);
                     $resqlseladmin = $this->db->query($sql, 1);
                     if ($resqlseladmin) {
                         $num = $this->db->num_rows($resqlseladmin);
                         $i = 0;
                         while ($i < $num) {
                             $obj2 = $this->db->fetch_object($resqlseladmin);
                             dol_syslog(get_class($this) . "::insert_permissions Add permission to user id=" . $obj2->rowid);
                             $tmpuser = new User($this->db);
                             $tmpuser->fetch($obj2->rowid);
                             if (!empty($tmpuser->id)) {
                                 $tmpuser->addrights($r_id);
                             }
                             $i++;
                         }
                         if (!empty($user->admin)) {
                             // We reload permissions
                             $user->clearrights();
                             $user->getrights();
                         }
                     } else {
                         dol_print_error($this->db);
                     }
                 }
             }
         }
         $this->db->free($resql);
     } else {
         $this->error = $this->db->lasterror();
         $err++;
     }
     return $err;
 }
Example #17
0
	if ($_GET["search_societe"])
	{
		$sql .= " AND s.nom like '%".$_GET["search_societe"]."%'";
	}

	if ($_GET["search_montant_ht"])
	{
		$sql .= " AND f.total_ht = '".$_GET["search_montant_ht"]."'";
	}

	if ($_GET["search_montant_ttc"])
	{
		$sql .= " AND f.total_ttc = '".$_GET["search_montant_ttc"]."'";
	}

	if (dol_strlen($_POST["sf_ref"]) > 0)
	{
		$sql .= " AND f.facnumber like '%".$_POST["sf_ref"] . "%'";
	}
	$sql.= " GROUP BY f.facnumber";

	$sql.= " ORDER BY ";
	$listfield=explode(',',$sortfield);
	foreach ($listfield as $key => $value) $sql.=$listfield[$key]." ".$sortorder.",";
	$sql.= " f.facnumber DESC";

	$result = $db->query($sql);

	if ($result)
	{
		$num = $db->num_rows($result);
Example #18
0
  */
 $head = group_prepare_head($fgroup);
 $title = $langs->trans("Group");
 dol_fiche_head($head, 'rights', $title, 0, 'group');
 // Charge les modules soumis a permissions
 $modules = array();
 $modulesdir = dolGetModulesDirs();
 $db->begin();
 foreach ($modulesdir as $dir) {
     // Load modules attributes in arrays (name, numero, orders) from dir directory
     //print $dir."\n<br>";
     $handle = @opendir(dol_osencode($dir));
     if (is_resource($handle)) {
         while (($file = readdir($handle)) !== false) {
             if (is_readable($dir . $file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
                 $modName = substr($file, 0, dol_strlen($file) - 10);
                 if ($modName) {
                     include_once $dir . "/" . $file;
                     $objMod = new $modName($db);
                     // Load all lang files of module
                     if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
                         foreach ($objMod->langfiles as $domain) {
                             $langs->load($domain);
                         }
                     }
                     // Load all permissions
                     if ($objMod->rights_class) {
                         $entity = !empty($conf->multicompany->enabled) && !empty($fgroup->entity) ? $fgroup->entity : null;
                         $ret = $objMod->insert_permissions(0, $entity);
                         $modules[$objMod->rights_class] = $objMod;
                     }
Example #19
0
 /**
  * Build a graph onto disk using Artichow library
  *
  * @param	string	$file    	Image file name to use if we save onto disk
  * @param	string	$fileurl	Url path to show image if saved onto disk
  * @return	void
  */
 private function draw_artichow($file, $fileurl)
 {
     global $artichow_defaultfont;
     dol_syslog(get_class($this) . "::draw_artichow this->type=" . join(',', $this->type));
     if (!defined('SHADOW_RIGHT_TOP')) {
         define('SHADOW_RIGHT_TOP', 3);
     }
     if (!defined('LEGEND_BACKGROUND')) {
         define('LEGEND_BACKGROUND', 2);
     }
     if (!defined('LEGEND_LINE')) {
         define('LEGEND_LINE', 1);
     }
     // Create graph
     $classname = '';
     if (!isset($this->type[0]) || $this->type[0] == 'bars') {
         $classname = 'BarPlot';
     } else {
         if ($this->type[0] == 'lines') {
             $classname = 'LinePlot';
         } else {
             $classname = 'TypeUnknown';
         }
     }
     include_once ARTICHOW_PATH . $classname . '.class.php';
     // Definition de couleurs
     $bgcolor = new Color($this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);
     $bgcolorgrid = new Color($this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
     $colortrans = new Color(0, 0, 0, 100);
     $colorsemitrans = new Color(255, 255, 255, 60);
     $colorgradient = new LinearGradient(new Color(235, 235, 235), new Color(255, 255, 255), 0);
     $colorwhite = new Color(255, 255, 255);
     // Graph
     $graph = new Graph($this->width, $this->height);
     $graph->border->hide();
     $graph->setAntiAliasing(true);
     if (isset($this->title)) {
         $graph->title->set($this->title);
         //print $artichow_defaultfont;exit;
         $graph->title->setFont(new $artichow_defaultfont(10));
     }
     if (is_array($this->bgcolor)) {
         $graph->setBackgroundColor($bgcolor);
     } else {
         $graph->setBackgroundGradient($colorgradient);
     }
     $group = new PlotGroup();
     //$group->setSpace(5, 5, 0, 0);
     $paddleft = 50;
     $paddright = 10;
     $strl = dol_strlen(max(abs($this->MaxValue), abs($this->MinValue)));
     if ($strl > 6) {
         $paddleft += $strl * 4;
     }
     $group->setPadding($paddleft, $paddright);
     // Width on left and right for Y axis values
     $group->legend->setSpace(0);
     $group->legend->setPadding(2, 2, 2, 2);
     $group->legend->setPosition(NULL, 0.1);
     $group->legend->setBackgroundColor($colorsemitrans);
     if (is_array($this->bgcolorgrid)) {
         $group->grid->setBackgroundColor($bgcolorgrid);
     } else {
         $group->grid->setBackgroundColor($colortrans);
     }
     if ($this->hideXGrid) {
         $group->grid->hideVertical(true);
     }
     if ($this->hideYGrid) {
         $group->grid->hideHorizontal(true);
     }
     // On boucle sur chaque lot de donnees
     $legends = array();
     $i = 0;
     $nblot = count($this->data[0]) - 1;
     while ($i < $nblot) {
         $x = 0;
         $values = array();
         foreach ($this->data as $key => $valarray) {
             $legends[$x] = $valarray[0];
             $values[$x] = $valarray[$i + 1];
             $x++;
         }
         // We fix unknown values to null
         $newvalues = array();
         foreach ($values as $val) {
             $newvalues[] = is_numeric($val) ? $val : null;
         }
         if ($this->type[0] == 'bars') {
             //print "Lot de donnees $i<br>";
             //print_r($values);
             //print '<br>';
             $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20);
             $colorbis = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 50);
             $colorgrey = new Color(100, 100, 100);
             $colorborder = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
             if ($this->mode == 'side') {
                 $plot = new BarPlot($newvalues, $i + 1, $nblot);
             }
             if ($this->mode == 'depth') {
                 $plot = new BarPlot($newvalues, 1, 1, ($nblot - $i - 1) * 5);
             }
             $plot->barBorder->setColor($colorgrey);
             //$plot->setBarColor($color);
             $plot->setBarGradient(new LinearGradient($colorbis, $color, 90));
             if ($this->mode == 'side') {
                 $plot->setBarPadding(0.1, 0.1);
             }
             if ($this->mode == 'depth') {
                 $plot->setBarPadding(0.1, 0.4);
             }
             if ($this->mode == 'side') {
                 $plot->setBarSpace(5);
             }
             if ($this->mode == 'depth') {
                 $plot->setBarSpace(2);
             }
             $plot->barShadow->setSize($this->SetShading);
             $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
             $plot->barShadow->setColor(new Color(160, 160, 160, 50));
             $plot->barShadow->smooth(TRUE);
             //$plot->setSize(1, 0.96);
             //$plot->setCenter(0.5, 0.52);
             // Le mode automatique est plus efficace
             $plot->SetYMax($this->MaxValue);
             $plot->SetYMin($this->MinValue);
         }
         if ($this->type[0] == 'lines') {
             $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20);
             $colorbis = new Color(min($this->datacolor[$i][0] + 20, 255), min($this->datacolor[$i][1] + 20, 255), min($this->datacolor[$i][2] + 20, 255), 60);
             $colorter = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 90);
             $plot = new LinePlot($newvalues);
             //$plot->setSize(1, 0.96);
             //$plot->setCenter(0.5, 0.52);
             $plot->setColor($color);
             $plot->setThickness(1);
             // Set line background gradient
             $plot->setFillGradient(new LinearGradient($colorter, $colorbis, 90));
             $plot->xAxis->setLabelText($legends);
             // Le mode automatique est plus efficace
             $plot->SetYMax($this->MaxValue);
             $plot->SetYMin($this->MinValue);
             //$plot->setYAxis(0);
             //$plot->hideLine(true);
         }
         //$plot->reduce(80);		// Evite temps d'affichage trop long et nombre de ticks absisce satures
         $group->legend->setTextFont(new $artichow_defaultfont(10));
         // This is to force Artichow to use awFileFontDriver to
         // solve a bug in Artichow with UTF8
         if (count($this->Legend)) {
             if ($this->type[0] == 'bars') {
                 $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
             }
             if ($this->type[0] == 'lines') {
                 $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
             }
         }
         $group->add($plot);
         $i++;
     }
     $group->axis->bottom->setLabelText($legends);
     $group->axis->bottom->label->setFont(new $artichow_defaultfont(7));
     //print $group->axis->bottom->getLabelNumber();
     if ($this->labelInterval > 0) {
         $group->axis->bottom->setLabelInterval($this->labelInterval);
     }
     $graph->add($group);
     // Generate file
     $graph->draw($file);
     $this->_stringtoshow = '<!-- Build using ' . $this->_library . ' --><img src="' . $fileurl . '" title="' . dol_escape_htmltag($this->title ? $this->title : $this->YLabel) . '" alt="' . dol_escape_htmltag($this->title ? $this->title : $this->YLabel) . '">';
 }
 /**
  *	Renvoi si un code respecte la syntaxe
  *
  *	@param	string		$code		Code a verifier
  *	@return	int						0 si OK, <0 si KO
  */
 function verif_syntax($code)
 {
     $res = 0;
     if (dol_strlen($code) < 11) {
         $res = -1;
     } else {
         $res = 0;
     }
     return $res;
 }
foreach ($dirmodels as $reldir) {
    foreach (array('', '/doc') as $valdir) {
        $dir = dol_buildpath($reldir . "core/modules/commande" . $valdir);
        if (is_dir($dir)) {
            $handle = opendir($dir);
            if (is_resource($handle)) {
                while (($file = readdir($handle)) !== false) {
                    $filelist[] = $file;
                }
                closedir($handle);
                arsort($filelist);
                foreach ($filelist as $file) {
                    if (preg_match('/\\.modules\\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
                        if (file_exists($dir . '/' . $file)) {
                            $name = substr($file, 4, dol_strlen($file) - 16);
                            $classname = substr($file, 0, dol_strlen($file) - 12);
                            require_once $dir . '/' . $file;
                            $module = new $classname($db);
                            $modulequalified = 1;
                            if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
                                $modulequalified = 0;
                            }
                            if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
                                $modulequalified = 0;
                            }
                            if ($modulequalified) {
                                $var = !$var;
                                print '<tr ' . $bc[$var] . '><td width="100">';
                                print empty($module->name) ? $name : $module->name;
                                print "</td><td>\n";
                                if (method_exists($module, 'info')) {
         $sendto = $thirdparty->email;
         $sendtoid = 0;
     } else {
         $sendto = $thirdparty->contact_get_property($_POST['receiver'], 'email');
         $sendtoid = $_POST['receiver'];
     }
 }
 if (dol_strlen($sendto)) {
     $langs->load("commercial");
     $from = $_POST['fromname'] . ' <' . $_POST['frommail'] . '>';
     $replyto = $_POST['replytoname'] . ' <' . $_POST['replytomail'] . '>';
     $message = $_POST['message'];
     $sendtocc = $_POST['sendtocc'];
     $deliveryreceipt = $_POST['deliveryreceipt'];
     if ($action == 'send' || $action == 'relance') {
         if (dol_strlen($_POST['subject'])) {
             $subject = $_POST['subject'];
         }
         $actionmsg2 = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
         if ($message) {
             $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
             $actionmsg .= $langs->transnoentities('MailTopic') . ": " . $subject . "\n";
             $actionmsg .= $langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
             $actionmsg .= $message;
         }
     }
     // Create form object
     include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
     $formmail = new FormMail($db);
     $attachedfiles = $formmail->get_attached_files();
     $filepath = $attachedfiles['paths'];
Example #23
0
 /**
  *  Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF
  *
  *  @param	string		$modele			force le modele a utiliser ('' par defaut)
  *  @param	Translate	$outputlangs	objet lang a utiliser pour traduction
  *  @param  int			$hidedetails    Hide details of lines
  *  @param  int			$hidedesc       Hide description
  *  @param  int			$hideref        Hide ref
  *  @return int         				0 if KO, 1 if OK
  */
 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $conf, $langs;
     $langs->load("projects");
     // Positionne modele sur le nom du modele de projet a utiliser
     if (!dol_strlen($modele)) {
         if (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
             $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
         } else {
             $modele = 'nodefault';
         }
     }
     $modelpath = "core/modules/project/task/doc/";
     return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
Example #24
0
            foreach ($dirsociete as $dirroot)
            {
                $res=dol_include_once($dirroot.$module.".php");
                if ($res) break;
            }
            $modCodeClient = new $module;
            // We verified if the tag prefix is used
            if ($modCodeClient->code_auto)
            {
                $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
            }
            $module=$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
            if (! $module) $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
            if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
            {
                $module = substr($module, 0, dol_strlen($module)-4);
            }
            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->societe_modules);
            foreach ($dirsociete as $dirroot)
            {
                $res=dol_include_once($dirroot.$module.".php");
                if ($res) break;
            }
            $modCodeFournisseur = new $module;
            // On verifie si la balise prefix est utilisee
            if ($modCodeFournisseur->code_auto)
            {
                $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
            }

            if (! empty($_POST["nom"]))
Example #25
0
 /**
  *    	\brief      Check if notification are active for couple action/company.
  * 					If yes, send mail and save trace into llx_notify.
  * 		\param		action		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  * 		\param		socid		Id of third party
  * 		\param		texte		Message to send
  * 		\param		objet_type	Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify.
  * 		\param		objet_id	Id of object the notification deals on
  * 		\param		file		Attach a file
  *		\return		int			<0 if KO, or number of changes if OK
  */
 function send($action, $socid, $texte, $objet_type, $objet_id, $file = "")
 {
     global $conf, $langs, $mysoc, $dolibarr_main_url_root;
     $langs->load("other");
     dol_syslog("Notify::send action={$action}, socid={$socid}, texte={$texte}, objet_type={$objet_type}, objet_id={$objet_id}, file={$file}");
     $sql = "SELECT s.nom, c.email, c.rowid as cid, c.name, c.firstname,";
     $sql .= " a.rowid as adid, a.label, a.code, n.rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,";
     $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,";
     $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
     $sql .= " " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
     $sql .= " AND n.fk_soc = s.rowid";
     if (is_numeric($action)) {
         $sql .= " AND n.fk_action = " . $action;
     } else {
         $sql .= " AND a.code = '" . $action . "'";
     }
     // New usage
     $sql .= " AND s.rowid = " . $socid;
     dol_syslog("Notify::send sql=" . $sql);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         while ($i < $num) {
             $obj = $this->db->fetch_object($result);
             $sendto = $obj->firstname . " " . $obj->name . " <" . $obj->email . ">";
             $actiondefid = $obj->adid;
             if (dol_strlen($sendto)) {
                 include_once DOL_DOCUMENT_ROOT . '/lib/files.lib.php';
                 $application = $conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM';
                 $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification");
                 $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
                 $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
                 $message .= "\n";
                 $message .= $texte;
                 // Add link
                 switch ($objet_type) {
                     case 'ficheinter':
                         $link = DOL_URL_ROOT . '/fichinter/fiche.php?id=' . $objet_id;
                         break;
                     case 'propal':
                         $link = DOL_URL_ROOT . '/comm/propal.php?id=' . $objet_id;
                         break;
                     case 'facture':
                         $link = DOL_URL_ROOT . '/compta/facture.php?facid=' . $objet_id;
                         break;
                     case 'order':
                         $link = DOL_URL_ROOT . '/commande/fiche.php?facid=' . $objet_id;
                         break;
                     case 'order_supplier':
                         $link = DOL_URL_ROOT . '/fourn/commande/fiche.php?facid=' . $objet_id;
                         break;
                 }
                 $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
                 if ($link) {
                     $message .= "\n" . $urlwithouturlroot . $link;
                 }
                 $filename = basename($file);
                 $mimefile = dol_mimetype($file);
                 $msgishtml = 0;
                 $replyto = $conf->notification->email_from;
                 $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[sizeof($filename) - 1]), '', '', 0, $msgishtml);
                 if ($mailfile->sendfile()) {
                     $sendto = htmlentities($sendto);
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
                     $sql .= " VALUES (" . $this->db->idate(mktime()) . ", " . $actiondefid . " ," . $obj->cid . " , '" . $objet_type . "', " . $objet_id . ", '" . $this->db->escape($obj->email) . "')";
                     dol_syslog("Notify::send sql=" . $sql);
                     if (!$this->db->query($sql)) {
                         dol_print_error($this->db);
                     }
                 } else {
                     $this->error = $mailfile->error;
                     //dol_syslog("Notify::send ".$this->error, LOG_ERR);
                 }
             }
             $i++;
         }
         return $i;
     } else {
         $this->error = $this->db->error();
         return -1;
     }
 }
Example #26
0
    define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
    define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
    define('NOREQUIREAJAX', '1');
}
//if (! defined("NOLOGIN"))        define("NOLOGIN",'1');
// Change this following line to use the correct relative path (../, ../../, etc)
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/cashdesk/include/environnement.php';
//header("Content-type: text/html; charset=UTF-8");
header("Content-type: text/html; charset=" . $conf->file->character_set_client);
// Search from criteria
if (dol_strlen($_GET["code"]) >= 0) {
    $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
    if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) {
        $sql .= ", ps.reel";
    }
    $sql .= " FROM " . MAIN_DB_PREFIX . "product as p";
    if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) {
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '" . $conf_fkentrepot . "'";
    }
    $sql .= " WHERE p.entity IN (" . getEntity('product', 1) . ")";
    $sql .= " AND p.tosell = 1";
    $sql .= " AND p.fk_product_type = 0";
    // Add criteria on ref/label
    if (!empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) {
        $sql .= " AND (p.ref LIKE '" . $_GET['code'] . "%' OR p.label LIKE '" . $_GET['code'] . "%')";
    } else {
 /**
  * Update object into database
  *
  * @param User $user that modifies
  * @param int $notrigger triggers after, 1=disable triggers
  * @param int $forceupdateaffiliate update price on each soc child
  * @return int <0 if KO, >0 if OK
  */
 function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0)
 {
     global $conf, $langs;
     $error = 0;
     // Clean parameters
     if (isset($this->entity)) {
         $this->entity = trim($this->entity);
     }
     if (isset($this->fk_product)) {
         $this->fk_product = trim($this->fk_product);
     }
     if (isset($this->fk_soc)) {
         $this->fk_soc = trim($this->fk_soc);
     }
     if (isset($this->price)) {
         $this->price = trim($this->price);
     }
     if (isset($this->price_ttc)) {
         $this->price_ttc = trim($this->price_ttc);
     }
     if (isset($this->price_min)) {
         $this->price_min = trim($this->price_min);
     }
     if (isset($this->price_min_ttc)) {
         $this->price_min_ttc = trim($this->price_min_ttc);
     }
     if (isset($this->price_base_type)) {
         $this->price_base_type = trim($this->price_base_type);
     }
     if (isset($this->tva_tx)) {
         $this->tva_tx = trim($this->tva_tx);
     }
     if (isset($this->recuperableonly)) {
         $this->recuperableonly = trim($this->recuperableonly);
     }
     if (isset($this->localtax1_tx)) {
         $this->localtax1_tx = trim($this->localtax1_tx);
     }
     if (isset($this->localtax2_tx)) {
         $this->localtax2_tx = trim($this->localtax2_tx);
     }
     if (isset($this->fk_user)) {
         $this->fk_user = trim($this->fk_user);
     }
     if (isset($this->import_key)) {
         $this->import_key = trim($this->import_key);
     }
     // Check parameters
     // Put here code to add a control on parameters values
     if ($this->price != '' || $this->price == 0) {
         if ($this->price_base_type == 'TTC') {
             $this->price_ttc = price2num($this->price, 'MU');
             $this->price = price2num($this->price) / (1 + $this->tva_tx / 100);
             $this->price = price2num($this->price, 'MU');
             if ($this->price_min != '' || $this->price_min == 0) {
                 $this->price_min_ttc = price2num($this->price_min, 'MU');
                 $this->price_min = price2num($this->price_min) / (1 + $this->tva_tx / 100);
                 $this->price_min = price2num($this->price_min, 'MU');
             } else {
                 $this->price_min = 0;
                 $this->price_min_ttc = 0;
             }
         } else {
             $this->price = price2num($this->price, 'MU');
             $this->price_ttc = $this->recuperableonly != 1 ? price2num($this->price) * (1 + $this->tva_tx / 100) : $this->price;
             $this->price_ttc = price2num($this->price_ttc, 'MU');
             if ($this->price_min != '' || $this->price_min == 0) {
                 $this->price_min = price2num($this->price_min, 'MU');
                 $this->price_min_ttc = price2num($this->price_min) * (1 + $this->tva_tx / 100);
                 $this->price_min_ttc = price2num($this->price_min_ttc, 'MU');
                 // print 'X'.$newminprice.'-'.$price_min;
             } else {
                 $this->price_min = 0;
                 $this->price_min_ttc = 0;
             }
         }
     }
     // Do a copy of current record into log table
     // Insert request
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price_log(";
     $sql .= "entity,";
     $sql .= "datec,";
     $sql .= "fk_product,";
     $sql .= "fk_soc,";
     $sql .= "price,";
     $sql .= "price_ttc,";
     $sql .= "price_min,";
     $sql .= "price_min_ttc,";
     $sql .= "price_base_type,";
     $sql .= "tva_tx,";
     $sql .= "recuperableonly,";
     $sql .= "localtax1_tx,";
     $sql .= "localtax2_tx,";
     $sql .= "fk_user,";
     $sql .= "import_key";
     $sql .= ") \t\t";
     $sql .= "SELECT";
     $sql .= " t.entity,";
     $sql .= " t.datec,";
     $sql .= " t.fk_product,";
     $sql .= " t.fk_soc,";
     $sql .= " t.price,";
     $sql .= " t.price_ttc,";
     $sql .= " t.price_min,";
     $sql .= " t.price_min_ttc,";
     $sql .= " t.price_base_type,";
     $sql .= " t.tva_tx,";
     $sql .= " t.recuperableonly,";
     $sql .= " t.localtax1_tx,";
     $sql .= " t.localtax2_tx,";
     $sql .= " t.fk_user,";
     $sql .= " t.import_key";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t";
     $sql .= " WHERE t.rowid = " . $this->id;
     $this->db->begin();
     dol_syslog(get_class($this) . "::update", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if (!$resql) {
         $error++;
         $this->errors[] = "Error " . $this->db->lasterror();
     }
     // Update request
     $sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET";
     $sql .= " entity=" . $conf->entity . ",";
     $sql .= " datec='" . $this->db->idate(dol_now()) . "',";
     $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ",";
     $sql .= " fk_product=" . (isset($this->fk_product) ? $this->fk_product : "null") . ",";
     $sql .= " fk_soc=" . (isset($this->fk_soc) ? $this->fk_soc : "null") . ",";
     $sql .= " price=" . (isset($this->price) ? $this->price : "null") . ",";
     $sql .= " price_ttc=" . (isset($this->price_ttc) ? $this->price_ttc : "null") . ",";
     $sql .= " price_min=" . (isset($this->price_min) ? $this->price_min : "null") . ",";
     $sql .= " price_min_ttc=" . (isset($this->price_min_ttc) ? $this->price_min_ttc : "null") . ",";
     $sql .= " price_base_type=" . (isset($this->price_base_type) ? "'" . $this->db->escape($this->price_base_type) . "'" : "null") . ",";
     $sql .= " tva_tx=" . (isset($this->tva_tx) ? $this->tva_tx : "null") . ",";
     $sql .= " recuperableonly=" . (isset($this->recuperableonly) ? $this->recuperableonly : "null") . ",";
     $sql .= " localtax1_tx=" . (isset($this->localtax1_tx) ? $this->localtax1_tx : "null") . ",";
     $sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? $this->localtax2_tx : "null") . ",";
     $sql .= " fk_user="******",";
     $sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . "";
     $sql .= " WHERE rowid=" . $this->id;
     dol_syslog(get_class($this) . "::update", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if (!$resql) {
         $error++;
         $this->errors[] = "Error " . $this->db->lasterror();
     }
     if (!$error) {
         if (!$notrigger) {
             // Uncomment this and change MYOBJECT to your own tag if you
             // want this action calls a trigger.
             // // Call triggers
             // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
             // $interface=new Interfaces($this->db);
             // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
             // if ($result < 0) { $error++; $this->errors=$interface->errors; }
             // // End call triggers
         }
     }
     if (!$error) {
         $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
         if ($result < 0) {
             $error++;
         }
     }
     // Commit or rollback
     if ($error) {
         foreach ($this->errors as $errmsg) {
             dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR);
             $this->error .= $this->error ? ', ' . $errmsg : $errmsg;
         }
         $this->db->rollback();
         return -1 * $error;
     } else {
         $this->db->commit();
         return 1;
     }
 }
 /**
  * 	Check validity of code according to its rules
  *
  *	@param	DoliDB		$db					Database handler
  *	@param	string		$code				Code to check/correct
  *	@param	Product		$product			Object product
  *  @param  int		  	$thirdparty_type   	0 = customer/prospect , 1 = supplier
  *  @param	string		$type       	    type of barcode (EAN, ISBN, ...)
  *  @return int								0 if OK
  * 											-1 ErrorBadCustomerCodeSyntax
  * 											-2 ErrorCustomerCodeRequired
  * 											-3 ErrorCustomerCodeAlreadyUsed
  * 											-4 ErrorPrefixRequired
  */
 function verif($db, &$code, $product, $thirdparty_type, $type)
 {
     global $conf;
     //var_dump($code.' '.$product->ref.' '.$thirdparty_type);exit;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
     $result = 0;
     $code = strtoupper(trim($code));
     if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) {
         $result = 0;
     } else {
         if (empty($code) && (!$this->code_null || !empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK))) {
             $result = -2;
         } else {
             if ($this->verif_syntax($code, $type) >= 0) {
                 $is_dispo = $this->verif_dispo($db, $code, $product);
                 if ($is_dispo != 0) {
                     $result = -3;
                 } else {
                     $result = 0;
                 }
             } else {
                 if (dol_strlen($code) == 0) {
                     $result = -2;
                 } else {
                     $result = -1;
                 }
             }
         }
     }
     dol_syslog(get_class($this) . "::verif type=" . $thirdparty_type . " result=" . $result);
     return $result;
 }
 /**		Return next value
  *      @param      objsoc      Object third party
  *      @param      ticket		Object ticket
  *      @param      mode        'next' for next value or 'last' for last value
  *      @return     string      Value if OK, 0 if KO
  */
 function getNextValue($objsoc, $facsim, $mode = 'next')
 {
     global $db, $conf;
     require_once DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php";
     // Get Mask value
     $mask = '';
     if (is_object($facsim) && $facsim->type == 2) {
         $mask = $conf->global->FACSIM_MURO_MASK_CREDIT;
     } else {
         $mask = $conf->global->FACSIM_MURO_MASK;
     }
     if (!$mask) {
         $this->error = 'NotConfigured';
         return 0;
     }
     $where = '';
     //ww para warehouse
     if (preg_match('/\\{(w+)\\}/i', $mask, $regWare)) {
         dol_include_once("/pos/class/cash.class.php");
         require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
         $terminal = new Cash($db);
         $terminal->fetch($facsim->fk_cash);
         $warehouse = new Entrepot($db);
         $warehouse->fetch($terminal->fk_warehouse);
         $maskware = $regWare[1];
         $maskware_value = substr($warehouse->libelle, 0, dol_strlen($regWare[1]));
         //get n first characters of warehouse ref where n is length in mask
         $maskware_value = str_pad($maskware_value, dol_strlen($regWare[1]), "#", STR_PAD_RIGHT);
         $maskware_maskbefore = '{' . $maskware . '}';
         $maskware_maskafter = $maskware_value;
         $mask = str_replace($maskware_maskbefore, $maskware_maskafter, $mask);
     }
     //kk para terminal
     if (preg_match('/\\{(k+)\\}/i', $mask, $regTerm)) {
         dol_include_once("/pos/class/cash.class.php");
         $terminal = new Cash($db);
         $terminal->fetch($facsim->fk_cash);
         $maskterm = $regTerm[1];
         $maskterm_value = substr($terminal->ref, 0, dol_strlen($regTerm[1]));
         //get n first characters of warehouse ref where n is length in mask
         $maskterm_value = str_pad($maskterm_value, dol_strlen($regTerm[1]), "#", STR_PAD_RIGHT);
         $maskterm_maskbefore = '{' . $maskterm . '}';
         $maskterm_maskafter = $maskterm_value;
         $mask = str_replace($maskterm_maskbefore, $maskterm_maskafter, $mask);
     }
     $numFinal = get_next_value($db, $mask, 'facture', 'facnumber', $where, $objsoc, time(), $mode);
     if (!preg_match('/([0-9])+/', $numFinal)) {
         $this->error = $numFinal;
     }
     return $numFinal;
 }
Example #30
0
	/**
	 *      \brief     Mets a jour une ligne de contrat
	 *      \param     rowid            Id de la ligne de facture
	 *      \param     desc             Description de la ligne
	 *      \param     pu               Prix unitaire
	 *      \param     qty              Quantite
	 *      \param     remise_percent   Pourcentage de remise de la ligne
	 *      \param     date_start       Date de debut prevue
	 *      \param     date_end         Date de fin prevue
	 *      \param     tvatx            Taux TVA
	 *      \param     localtax1tx      Local tax 1 rate
	 *      \param     localtax2tx      Local tax 2 rate
	 *      \param     date_debut_reel  Date de debut reelle
	 *      \param     date_fin_reel    Date de fin reelle
	 *      \return    int              < 0 si erreur, > 0 si ok
	 */
	function updateline($rowid, $desc, $pu, $qty, $remise_percent=0,
	$date_start='', $date_end='', $tvatx, $localtax1tx=0, $localtax2tx=0,
	$date_debut_reel='', $date_fin_reel='')
	{
		global $user, $conf, $langs;

		// Nettoyage parametres
		$qty=trim($qty);
		$desc=trim($desc);
		$desc=trim($desc);
		$price = price2num($pu);
		$tvatx = price2num($tvatx);
		$localtax1tx = price2num($localtax1tx);
		$localtax2tx = price2num($localtax2tx);
		$subprice = $price;
		$remise = 0;
		if (dol_strlen($remise_percent) > 0)
		{
			$remise = round(($pu * $remise_percent / 100), 2);
			$price = $pu - $remise;
		}
		else
		{
			$remise_percent=0;
		}

		dol_syslog("Contrat::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $date_debut_reel, $date_fin_reel, $tvatx, $localtax1tx, $localtax2tx");

		$this->db->begin();

		$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".$this->db->escape($desc)."'";
		$sql .= ",price_ht='" .     price2num($price)."'";
		$sql .= ",subprice='" .     price2num($subprice)."'";
		$sql .= ",remise='" .       price2num($remise)."'";
		$sql .= ",remise_percent='".price2num($remise_percent)."'";
		$sql .= ",qty='$qty'";
		$sql .= ",tva_tx='".        price2num($tvatx)."'";
		$sql .= ",localtax1_tx='".        price2num($localtax1tx)."'";
		$sql .= ",localtax2_tx='".        price2num($localtax2tx)."'";
		if ($date_start > 0) { $sql.= ",date_ouverture_prevue=".$this->db->idate($date_start); }
		else { $sql.=",date_ouverture_prevue=null"; }
		if ($date_end > 0) { $sql.= ",date_fin_validite=".$this->db->idate($date_end); }
		else { $sql.=",date_fin_validite=null"; }
		if ($date_debut_reel > 0) { $sql.= ",date_ouverture=".$this->db->idate($date_debut_reel); }
		else { $sql.=",date_ouverture=null"; }
		if ($date_fin_reel > 0) { $sql.= ",date_cloture=".$this->db->idate($date_fin_reel); }
		else { $sql.=",date_cloture=null"; }
		$sql .= " WHERE rowid = ".$rowid;

		dol_syslog("Contrat::UpdateLine sql=".$sql);
		$result = $this->db->query($sql);
		if ($result)
		{
			$result=$this->update_statut($user);
			if ($result >= 0)
			{
				$this->db->commit();
				return 1;
			}
			else
			{
				$this->db->rollback();
				dol_syslog("Contrat::UpdateLigne Erreur -2");
				return -2;
			}
		}
		else
		{
			$this->db->rollback();
			$this->error=$this->db->error();
			dol_syslog("Contrat::UpdateLigne Erreur -1");
			return -1;
		}
	}