Bonjour à tous,

Ci-joint un patch qui ajoute un logo pour les clients. 

Modification de la table llx_societe (le patch ajoute la colonne logo dans la 
table, ou l'ajoute en cas de migration).

Le logo est redimensionné, et peut-être affiché en plus grand en cliquant 
dessus via le plugin lightbox de jQuery.

--------------------------------------------
Dimitri Mouilllard
Développeur
Teclib' -  5, rue Jean Perrin, 28600 Luisant
Mail : [email protected]
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents install/mysql/migration/2.9.0-3.0.0.sql install/mysql/migration/2.9.0-3.0.0.sql
--- install/mysql/migration/2.9.0-3.0.0.sql	2011-03-16 13:06:56.000000000 +0100
+++ install/mysql/migration/2.9.0-3.0.0.sql	2011-04-26 16:40:38.000000000 +0200
@@ -47,6 +47,7 @@
 
 ALTER TABLE llx_societe ADD COLUMN canvas varchar(32) DEFAULT NULL AFTER default_lang;
 ALTER TABLE llx_societe MODIFY canvas varchar(32) DEFAULT NULL;
+ALTER TABLE llx_societe ADD COLUMN logo varchar(255) DEFAULT NULL;
 
 ALTER TABLE llx_cond_reglement RENAME TO llx_c_payment_term;
 ALTER TABLE llx_expedition_methode RENAME TO llx_c_shipment_mode;
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents install/mysql/tables/llx_societe.sql install/mysql/tables/llx_societe.sql
--- install/mysql/tables/llx_societe.sql	2011-01-26 11:00:27.000000000 +0100
+++ install/mysql/tables/llx_societe.sql	2011-04-27 09:10:36.000000000 +0200
@@ -82,5 +82,6 @@
   price_level              integer NULL,                        		-- level of price for multiprices
   default_lang             varchar(6),									-- default language
   canvas				   varchar(32),			                        -- type of canvas if used (null by default)
-  import_key               varchar(14)                          		-- import key
+  import_key               varchar(14),                          		-- import key
+  logo               varchar(255)                          		-- logo
 )type=innodb;
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents main.inc.php main.inc.php
--- main.inc.php	2011-04-04 01:15:24.000000000 +0200
+++ main.inc.php	2011-04-26 16:40:38.000000000 +0200
@@ -859,6 +859,7 @@
             if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
             print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui-latest.custom.css" type="text/css" />'."\n";
             print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/tooltip/jquery.tooltip.css" type="text/css" />'."\n";
+            print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/lightbox/css/jquery.lightbox-0.5.css" type="text/css" />'."\n";
         }
 
         print '<!-- Includes for Dolibarr, modules or specific pages-->'."\n";
@@ -902,6 +903,7 @@
 			print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui-latest.custom.min'.$ext.'"></script>'."\n";
 			print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd_0_5'.$ext.'"></script>'."\n";
 			print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tooltip/jquery.tooltip.min'.$ext.'"></script>'."\n";
+			print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/lightbox/js/jquery.lightbox-0.5.min'.$ext.'"></script>'."\n";
 
 			if ($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT || defined('REQUIRE_JQUERY_LAYOUT'))
 			{
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents societe/class/societe.class.php societe/class/societe.class.php
--- societe/class/societe.class.php	2011-04-04 01:15:59.000000000 +0200
+++ societe/class/societe.class.php	2011-04-27 09:06:19.000000000 +0200
@@ -197,11 +197,11 @@
 
         if ($result >= 0)
         {
-            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, datea, fk_user_creat, canvas)";
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, datea, fk_user_creat, canvas, logo)";
             $sql.= " VALUES ('".$this->db->escape($this->nom)."', ".$conf->entity.", '".$this->db->idate($now)."', '".$this->db->idate($now)."'";
             $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null");
             $sql.= ", ".($this->canvas ? "'".$this->canvas."'":"null");
-            $sql.= ")";
+            $sql.= " , '".$this->logo."')";
 
             dol_syslog("Societe::create sql=".$sql);
             $result=$this->db->query($sql);
@@ -467,7 +467,7 @@
             $sql .= ",fournisseur = " . ($this->fournisseur?$this->fournisseur:0);
             $sql .= ",gencod = ".($this->gencod?"'".$this->gencod."'":"null");
             $sql .= ",default_lang = ".($this->default_lang?"'".$this->default_lang."'":"null");
-
+            $sql .= ",logo = '".$this->logo."'";
 
             if ($allowmodcodeclient)
             {
@@ -567,13 +567,14 @@
         $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.gencod';
         $sql .= ', s.fk_departement, s.fk_pays, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj';
         $sql .= ', s.localtax1_assuj, s.localtax2_assuj, s.fk_prospectlevel, s.default_lang';
-        $sql .= ', s.import_key';
+        $sql .= ', s.import_key, s.logo';
         $sql .= ', fj.libelle as forme_juridique';
         $sql .= ', e.libelle as effectif';
         $sql .= ', p.code as pays_code, p.libelle as pays';
         $sql .= ', d.code_departement as departement_code, d.nom as departement';
         $sql .= ', st.libelle as stcomm';
         $sql .= ', te.code as typent_code';
+        $sql .= ', s.logo';
         $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
         $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
         $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid';
@@ -701,6 +702,8 @@
                 $this->price_level = $obj->price_level;
 
                 $this->import_key = $obj->import_key;
+                
+                $this->logo = $obj->logo;
 
                 $result = 1;
             }
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents societe/soc.php societe/soc.php
--- societe/soc.php	2011-01-30 13:43:35.000000000 +0100
+++ societe/soc.php	2011-04-27 09:06:08.000000000 +0200
@@ -35,6 +35,8 @@
 require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
 require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
 require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
 if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
 
 $langs->load("companies");
@@ -149,7 +151,42 @@
 		$soc->code_fournisseur      = $_POST["code_fournisseur"];
 		$soc->capital               = $_POST["capital"];
 		$soc->gencod                = $_POST["gencod"];
-
+      
+      ### Gestion du logo de la société
+      $file_max_size 		= 2 * 1024 * 1024; 
+   	$file_extensions 	= "/^\.(jpg|jpeg|gif|png){1}$/i";
+   	$file_destination 	= $conf->societe->dir_output."/logos/";
+   	if(!is_dir($file_destination)) {
+   	   create_exdir(DOL_DATA_ROOT."/societe/logos/");
+   	   create_exdir(DOL_DATA_ROOT."/societe/logos/thumbs/");
+   	}
+   	$file_OK 			= is_uploaded_file($_FILES['logo']['tmp_name']);
+
+   	if($file_OK){
+   		$file_namesafe = preg_replace(array("/\s+/", "/[^-\.\w]+/"),array("_", ""),trim($_FILES['logo']['name']));
+   		if ($_FILES['logo']['size'] <= $file_max_size){
+   		   if(preg_match($file_extensions,strrchr($file_namesafe,'.'))){
+   		      $file_move = dol_move_uploaded_file($_FILES['logo']['tmp_name'],$file_destination.$file_namesafe,1);
+   		      if($file_move > 0){
+   		         $soc->logo = $file_namesafe;
+                  
+                  # On récupère la taille de l'image en pixel
+   		         $imageWidth = dol_getImageSize($file_destination.$file_namesafe);
+                     
+                     # Si supérieur à 640 pixels, on redimensionne
+                     if($imageWidth['width'] > 640) {
+   		               dol_imageResizeOrCrop($file_destination.$file_namesafe,0,640,0);
+   		            }
+                  
+                  # On crée une miniature de l'image
+   		         vignette($file_destination.$file_namesafe, 180, 90, '', 75, '/thumbs/', 0);
+
+   		      }
+   		   }
+   		}
+   	}
+   	### Gestion du logo de la société
+   	
 		$soc->tva_assuj             = $_POST["assujtva_value"];
 
 		// Local Taxes
@@ -534,6 +571,41 @@
 		require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
 		$modCodeFournisseur = new $module;
 
+      ### Gestion du logo de la société
+      $file_max_size 		= 2 * 1024 * 1024; 
+   	$file_extensions 	= "/^\.(jpg|jpeg|gif|png){1}$/i";
+   	$file_destination 	= $conf->societe->dir_output."/logos/";
+   	if(!is_dir($file_destination)) {
+   	   create_exdir(DOL_DATA_ROOT."/societe/logos/");
+   	   create_exdir(DOL_DATA_ROOT."/societe/logos/thumbs/");
+   	}
+   	$file_OK 			= is_uploaded_file($_FILES['logo']['tmp_name']);
+
+   	if($file_OK){
+   		$file_namesafe = preg_replace(array("/\s+/", "/[^-\.\w]+/"),array("_", ""),trim($_FILES['logo']['name']));
+   		if ($_FILES['logo']['size'] <= $file_max_size){
+   		   if(preg_match($file_extensions,strrchr($file_namesafe,'.'))){
+   		      $file_move = dol_move_uploaded_file($_FILES['logo']['tmp_name'],$file_destination.$file_namesafe,1);
+   		      if($file_move > 0){
+   		         $soc->logo = $file_namesafe;
+                  
+                  # On récupère la taille de l'image en pixel
+   		         $imageWidth = dol_getImageSize($file_destination.$file_namesafe);
+                     
+                     # Si supérieur à 640 pixels, on redimensionne
+                     if($imageWidth['width'] > 640) {
+   		               dol_imageResizeOrCrop($file_destination.$file_namesafe,0,640,0);
+   		            }
+                  
+                  # On crée une miniature de l'image
+   		         vignette($file_destination.$file_namesafe, 180, 90, '', 75, '/thumbs/', 0);
+
+   		      }
+   		   }
+   		}
+   	}
+   	### Gestion du logo de la société
+   	
 		/*
 		 * Company Fact creation mode
 		 */
@@ -652,7 +724,7 @@
 
 		dol_htmloutput_errors($soc->error,$soc->errors);
 
-		print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
+		print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
 
 		print '<input type="hidden" name="action" value="add">';
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -924,7 +996,13 @@
 			print '</td></tr>';
 		}
 
-
+                // Ajout du logo
+		print '<tr>';
+		   print '<td>'.$langs->trans("Logo").'</td>';
+         print '<td colspan="3">';
+         print '<input type="file" name="logo" />';
+         print '</td>';
+      print '</tr>';
 
 		print '<tr><td colspan="4" align="center">';
 		print '<input type="submit" class="button" value="'.$langs->trans('AddThirdParty').'">';
@@ -978,6 +1056,42 @@
 			}
 			else
 			{
+		
+            ### Gestion du logo de la société
+            $file_max_size 		= 2 * 1024 * 1024; 
+         	$file_extensions 	= "/^\.(jpg|jpeg|gif|png){1}$/i";
+         	$file_destination 	= $conf->societe->dir_output."/logos/";
+         	if(!is_dir($file_destination)) {
+         	   create_exdir(DOL_DATA_ROOT."/societe/logos/");
+         	   create_exdir(DOL_DATA_ROOT."/societe/logos/thumbs/");
+         	}
+         	$file_OK 			= is_uploaded_file($_FILES['logo']['tmp_name']);
+
+         	if($file_OK){
+         		$file_namesafe = preg_replace(array("/\s+/", "/[^-\.\w]+/"),array("_", ""),trim($_FILES['logo']['name']));
+         		if ($_FILES['logo']['size'] <= $file_max_size){
+         		   if(preg_match($file_extensions,strrchr($file_namesafe,'.'))){
+         		      $file_move = dol_move_uploaded_file($_FILES['logo']['tmp_name'],$file_destination.$file_namesafe,1);
+         		      if($file_move > 0){
+         		         $soc->logo = $file_namesafe;
+
+                        # On récupère la taille de l'image en pixel
+         		         $imageWidth = dol_getImageSize($file_destination.$file_namesafe);
+
+                           # Si supérieur à 640 pixels, on redimensionne
+                           if($imageWidth['width'] > 640) {
+         		               dol_imageResizeOrCrop($file_destination.$file_namesafe,0,640,0);
+         		            }
+
+                        # On crée une miniature de l'image
+         		         vignette($file_destination.$file_namesafe, 180, 90, '', 75, '/thumbs/', 0);
+
+         		      }
+         		   }
+         		}
+         	}
+         	### Gestion du logo de la société
+   	
 				$soc->id=$_POST["socid"];
 				$soc->nom=$_POST["nom"];
 				$soc->prefix_comm=$_POST["prefix_comm"];
@@ -1045,7 +1159,7 @@
 				print '</script>'."\n";
 			}
 
-			print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$soc->id.'" method="post" name="formsoc">';
+			print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$soc->id.'" method="post" name="formsoc">';
 			print '<input type="hidden" name="action" value="update">';
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 			print '<input type="hidden" name="socid" value="'.$soc->id.'">';
@@ -1056,6 +1170,12 @@
 			// Name
 			print '<tr><td><span class="fieldrequired">'.$langs->trans('Name').'</span></td><td colspan="3"><input type="text" size="40" maxlength="60" name="nom" value="'.$soc->nom.'"></td></tr>';
 
+                        // Logo
+   		        print '<tr>';
+   		        print '<td><span class="fieldrequired">'.$langs->trans("Logo").'</span></td>';
+                        print '<td colspan="3"><input type="file" name="logo" /></td>';
+                        print '</tr>';
+         
 			// Prefix
 			print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
 			// It does not change the prefix mode using the auto numbering prefix
@@ -1357,13 +1477,22 @@
 			print '</div>';
 		}
 
-		print '<form name="formsoc" method="post">';
+               print "<script type=\"text/javascript\">
+   	              $(function() {
+   	              $('#logoSociete').lightBox({overlayOpacity:0.5});
+   	              });
+                      </script>";
+
+		print '<form enctype="multipart/form-data" name="formsoc" method="post">';
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 		print '<table class="border" width="100%">';
 
-		// Name
-		print '<tr><td width="20%">'.$langs->trans('Name').'</td>';
-		print '<td colspan="3">';
+		// Name + Logo
+		print '<tr>';
+		print '<td rowspan="4" style="text-align: center;"><a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=societe&file='.$soc->logo.'" id="logoSociete">'."\n";
+   	        print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=societe&file=/thumbs/'.$soc->logo.'" /></a></td>';
+   	        print '<td width="20%">'.$langs->trans('Name').'</td>';
+		print '<td colspan="2">';
 		print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom');
 		print '</td></tr>';
 
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' --exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php --exclude=documents viewimage.php viewimage.php
--- viewimage.php	2011-03-30 10:14:54.000000000 +0200
+++ viewimage.php	2011-04-26 16:40:38.000000000 +0200
@@ -67,6 +67,13 @@
 {
 	// Check permissions and define directory
 
+	// Wrapping pour les images des societes
+	if ($modulepart == 'societe')
+	{
+		$accessallowed=1;
+		$original_file=$conf->dir_output.'/logos/'.$original_file;
+	}
+	
 	// Wrapping for company logo
 	if ($modulepart == 'companylogo')
 	{
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

Répondre à