Work on multicompany module with smarty integration

This commit is contained in:
Regis Houssin 2009-10-29 15:42:36 +00:00
parent 739b230b86
commit 03ff1d83c7
6 changed files with 63 additions and 23 deletions

View File

@ -38,6 +38,12 @@ accessforbidden();
* Actions * Actions
*/ */
if ($_GET["action"] == 'enable' || $_GET["action"] == 'disable')
{
$mc = new Multicompany($db);
$mc->setEntity($_GET['id'],$_GET["action"]);
}
llxHeader('',$langs->trans("MultiCompanySetup")); llxHeader('',$langs->trans("MultiCompanySetup"));
@ -46,7 +52,7 @@ print_fiche_titre($langs->trans("MultiCompanySetup"),$linkback,'setup');
/* /*
* * View
*/ */
print '<br>'; print '<br>';

View File

@ -344,7 +344,7 @@ while (($file = readdir($handle))!==false)
print $module->description; print $module->description;
print '</td>'; print '</td>';
// Activ<EFBFBD> // Activate
if (in_array($name, $def)) if (in_array($name, $def))
{ {
print "<td align=\"center\">\n"; print "<td align=\"center\">\n";
@ -367,7 +367,7 @@ while (($file = readdir($handle))!==false)
print "</td>"; print "</td>";
} }
// Defaut // Default
print "<td align=\"center\">"; print "<td align=\"center\">";
if ($conf->global->PROPALE_ADDON_PDF == "$name") if ($conf->global->PROPALE_ADDON_PDF == "$name")
{ {
@ -411,7 +411,7 @@ print '<br>';
/* /*
* Autres options * Other options
* *
*/ */
print_titre($langs->trans("OtherOptions")); print_titre($langs->trans("OtherOptions"));
@ -495,7 +495,7 @@ print '</table>';
/* /*
* Repertoire * Directory
*/ */
print '<br>'; print '<br>';
print_titre($langs->trans("PathToDocuments")); print_titre($langs->trans("PathToDocuments"));

View File

@ -759,11 +759,14 @@ class DolibarrModules
$val = $this->const[$key][2]; $val = $this->const[$key][2];
$note = $this->const[$key][3]; $note = $this->const[$key][3];
$visible= $this->const[$key][4]; $visible= $this->const[$key][4];
$entity = $this->const[$key][5];
$entity = ((!empty($entity) || $entity == 0)?$entity:$conf->entity);
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'"; $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$entity;
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
@ -782,7 +785,7 @@ class DolibarrModules
$sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1);
$sql.= ",'".$note."'"; $sql.= ",'".$note."'";
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$conf->entity; $sql.= ",".$entity;
$sql.= ")"; $sql.= ")";
} }
elseif (strlen($val)) elseif (strlen($val))
@ -793,7 +796,7 @@ class DolibarrModules
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1);
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$conf->entity; $sql.= ",".$entity;
$sql.= ")"; $sql.= ")";
} }
else else
@ -803,7 +806,7 @@ class DolibarrModules
$sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1);
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$conf->entity; $sql.= ",".$entity;
$sql.= ")"; $sql.= ")";
} }
@ -816,7 +819,7 @@ class DolibarrModules
} }
else else
{ {
dol_syslog("DolibarrModules::insert_const constant '".$name."' alreday exists"); dol_syslog("DolibarrModules::insert_const constant '".$name."' already exists");
} }
} }
else else

View File

@ -70,7 +70,7 @@ class modMultiCompany extends DolibarrModules
$this->picto='globe'; $this->picto='globe';
// Data directories to create when module is enabled. // Data directories to create when module is enabled.
$this->dirs = array(); $this->dirs = array('/smarty/cache/temp','/smarty/templates/temp');
// Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'. // Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'.
$this->style_sheet = ''; $this->style_sheet = '';
@ -86,10 +86,12 @@ class modMultiCompany extends DolibarrModules
$this->langfiles = array("multicompany"); $this->langfiles = array("multicompany");
// Constants // Constants
$this->const = array(); // List of particular constants to add when module is enabled // List of particular constants to add when module is enabled
//Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0), //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0),
// 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) ); // 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) );
$this->const=array(1=>array('MAIN_MODULE_MULTICOMPANY_NEEDSMARTY',"chaine",1,'Need smarty',0,0));
// Array to add new pages in new tabs // Array to add new pages in new tabs
//$this->tabs = array('entity:Title:@mymodule:/mymodule/mynewtab.php?id=__ID__'); //$this->tabs = array('entity:Title:@mymodule:/mymodule/mynewtab.php?id=__ID__');
// where entity can be // where entity can be

View File

@ -89,6 +89,32 @@ class Multicompany
} }
/**
* \brief Enable/disable entity
*/
function setEntity($id,$action)
{
global $conf;
if ($action == 'enable')
{
$newid = str_replace('-','',$id);
}
else if ($action == 'disable')
{
$newid = '-'.$id;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."const";
$sql.= " SET entity = ".$newid;
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'";
$sql.= " AND entity = ".$id;
dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
}
/** /**
* \brief List of entities * \brief List of entities
*/ */
@ -96,12 +122,13 @@ class Multicompany
{ {
global $conf; global $conf;
$sql = "SELECT ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql = "SELECT ";
$sql.= $this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", visible"; $sql.= ", visible";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'"; $sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'";
$sql.= " ORDER BY entity ASC"; $sql.= " ORDER BY value ASC";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
@ -139,12 +166,14 @@ class Multicompany
{ {
foreach ($entities as $entity) foreach ($entities as $entity)
{ {
print '<option value="'.$entity['id'].'" '; if ($entity['active'] == 1)
if ($selected == $entity['id']) print 'selected="true"'; {
if ($entity['active'] == 0) print 'disabled="disabled"'; print '<option value="'.$entity['id'].'" ';
print '>'; if ($selected == $entity['id']) print 'selected="true"';
print $entity['label']; print '>';
print '</option>'; print $entity['label'];
print '</option>';
}
} }
} }
print '</select>'; print '</select>';
@ -166,7 +195,7 @@ class Multicompany
$smarty->assign('entities',$this->entities); $smarty->assign('entities',$this->entities);
$smarty->assign('img_on',img_picto($langs->trans("Activated"),'on')); $smarty->assign('img_on',img_picto($langs->trans("Activated"),'on'));
$smarty->assign('img_off',img_picto($langs->trans("Disabled"),'on')); $smarty->assign('img_off',img_picto($langs->trans("Disabled"),'off'));
} }

View File

@ -34,9 +34,9 @@
<td align="center"> <td align="center">
{if $entities[mc].active} {if $entities[mc].active}
{$img_on} <a href="{$smarty.server.SCRIPT_NAME}?action=disable&amp;id={$entities[mc].id}">{$img_on}</a>
{else} {else}
{$img_off} <a href="{$smarty.server.SCRIPT_NAME}?action=enable&amp;id={$entities[mc].id}">{$img_off}</a>
{/if} {/if}
</td> </td>