mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
set Default values as CURD classes
This commit is contained in:
parent
1b57d2a4a0
commit
f62386a6a5
|
|
@ -83,7 +83,7 @@ if ($action == 'set') {
|
|||
dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
|
||||
|
||||
$defaultValues = new DefaultValues($db);
|
||||
$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity));
|
||||
$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
|
||||
if (!is_array($result) && $result<0) {
|
||||
setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
|
||||
} elseif(count($result)>0) {
|
||||
|
|
@ -358,7 +358,7 @@ print '<td class="center"> </td>'."\n";
|
|||
print '<td class="right nowrap">'."\n";
|
||||
$defval='na';
|
||||
$defaultValues = new DefaultValues($db);
|
||||
$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity));
|
||||
$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
|
||||
if (!is_array($result) && $result<0) {
|
||||
setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
|
||||
} elseif(count($result)>0) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ $id = GETPOST('rowid', 'int');
|
|||
$action = GETPOST('action', 'aZ09');
|
||||
$optioncss = GETPOST('optionscss', 'alphanohtml');
|
||||
|
||||
$mode = GETPOST('mode', 'aZ09') ?GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus'
|
||||
$mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus'
|
||||
|
||||
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
|
||||
$sortfield = GETPOST("sortfield", 'alpha');
|
||||
|
|
@ -138,13 +138,12 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac
|
|||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->begin();
|
||||
|
||||
if ($action == 'add' || (GETPOST('add') && $action != 'update')) {
|
||||
$object->type=$mode;
|
||||
$object->user_id=0;
|
||||
$object->page=$defaulturl;
|
||||
$object->param=$defaulturl;
|
||||
$object->param=$defaultkey;
|
||||
$object->value=$defaultvalue;
|
||||
$object->entity=$conf->entity;
|
||||
$result=$object->create($user);
|
||||
|
|
@ -162,9 +161,11 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac
|
|||
if (GETPOST('actionmodify'))
|
||||
{
|
||||
$object->id=$id;
|
||||
$object->page=$defaulturl;
|
||||
$object->type=$mode;
|
||||
$object->page=$urlpage;
|
||||
$object->param=$key;
|
||||
$object->value=$defaultvalue;
|
||||
$object->value=$value;
|
||||
$object->entity=$conf->entity;
|
||||
$result=$object->update($user);
|
||||
if ($result<0) {
|
||||
$action = '';
|
||||
|
|
@ -358,8 +359,9 @@ print '</tr>';
|
|||
$result=$object->fetchAll( $sortorder, $sortfield, 0, 0, array('t.type'=>$mode,'t.entity'=>array($user->entity,$conf->entity)));
|
||||
|
||||
if (!is_array($result) && $result<0) {
|
||||
|
||||
setEventMessages($object->error, $object->errors,'errors');
|
||||
} else {
|
||||
} elseif (count($result)>0) {
|
||||
foreach($result as $key=>$defaultvalue) {
|
||||
print "\n";
|
||||
|
||||
|
|
@ -367,13 +369,13 @@ if (!is_array($result) && $result<0) {
|
|||
|
||||
// Page
|
||||
print '<td>';
|
||||
if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->rowid) print $defaultvalue->page;
|
||||
if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->id) print $defaultvalue->page;
|
||||
else print '<input type="text" name="urlpage" value="'.dol_escape_htmltag($defaultvalue->page).'">';
|
||||
print '</td>'."\n";
|
||||
|
||||
// Field
|
||||
print '<td>';
|
||||
if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print $defaultvalue->param;
|
||||
if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) print $defaultvalue->param;
|
||||
else print '<input type="text" name="key" value="'.dol_escape_htmltag($defaultvalue->param).'">';
|
||||
print '</td>'."\n";
|
||||
|
||||
|
|
@ -385,7 +387,7 @@ if (!is_array($result) && $result<0) {
|
|||
print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->transkey.'">';
|
||||
print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.dol_escape_htmltag($obj->transvalue).'">';
|
||||
*/
|
||||
if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print dol_escape_htmltag($defaultvalue->value);
|
||||
if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) print dol_escape_htmltag($defaultvalue->value);
|
||||
else print '<input type="text" name="value" value="'.dol_escape_htmltag($defaultvalue->value).'">';
|
||||
print '</td>';
|
||||
}
|
||||
|
|
@ -400,7 +402,7 @@ if (!is_array($result) && $result<0) {
|
|||
} else {
|
||||
print '<input type="hidden" name="page" value="'.$page.'">';
|
||||
print '<input type="hidden" name="rowid" value="'.$id.'">';
|
||||
print '<div name="'.(!empty($defaultvalue->id) ? $obj->rowid : 'none').'"></div>';
|
||||
print '<div name="'.(!empty($defaultvalue->id) ? $defaultvalue->id : 'none').'"></div>';
|
||||
print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
|
||||
print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,13 +265,12 @@ class DefaultValues extends CommonObject
|
|||
$sql = 'SELECT ';
|
||||
$sql .= $this->getFieldList();
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
|
||||
else $sql .= ' WHERE 1 = 1';
|
||||
$sql .= ' WHERE 1 = 1';
|
||||
// Manage filter
|
||||
$sqlwhere = array();
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || $key == 't.user_id') {
|
||||
if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || ($key == 't.user_id' && !is_array($value))) {
|
||||
$sqlwhere[] = $key.'='.$value;
|
||||
} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
|
||||
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
|
||||
|
|
@ -296,10 +295,12 @@ class DefaultValues extends CommonObject
|
|||
if (!empty($limit)) {
|
||||
$sql .= ' '.$this->db->plimit($limit, $offset);
|
||||
}
|
||||
|
||||
print $sql;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
$num = $this->db->num_rows($resql);
|
||||
var_dump($num);
|
||||
$i = 0;
|
||||
while ($i < ($limit ? min($limit, $num) : $num))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -611,31 +611,32 @@ class User extends CommonObject
|
|||
public function loadDefaultValues()
|
||||
{
|
||||
global $conf;
|
||||
if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
|
||||
|
||||
// Load user->default_values for user. TODO Save this in memcached ?
|
||||
$sql = "SELECT rowid, entity, type, page, param, value";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."default_values";
|
||||
$sql .= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity
|
||||
$sql .= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined)
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) {
|
||||
// $obj->page is relative URL with or without params
|
||||
// $obj->type can be 'filters', 'sortorder', 'createform', ...
|
||||
// $obj->param is key or param
|
||||
$pagewithoutquerystring = $obj->page;
|
||||
$pagequeries = '';
|
||||
$reg = array();
|
||||
if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param
|
||||
$pagewithoutquerystring = $reg[1];
|
||||
$pagequeries = $reg[2];
|
||||
// Load user->default_values for user. TODO Save this in memcached ?
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php';
|
||||
|
||||
$defaultValues = new DefaultValues($this->db);
|
||||
$result = $defaultValues->fetchAll('','',0,0,array('t.user_id'=>array(0,$this->id), 'entity'=>array($this->entity,$conf->entity)));
|
||||
|
||||
if (!is_array($result) && $result<0) {
|
||||
setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
} elseif(count($result)>0) {
|
||||
foreach($result as $defval) {
|
||||
if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
|
||||
$pagewithoutquerystring = $defval->page;
|
||||
$pagequeries = '';
|
||||
$reg = array();
|
||||
if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param
|
||||
$pagewithoutquerystring = $reg[1];
|
||||
$pagequeries = $reg[2];
|
||||
}
|
||||
$this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries : '_noquery_'][$defval->param] = $defval->value;
|
||||
}
|
||||
$this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries ? $pagequeries : '_noquery_'][$obj->param] = $obj->value;
|
||||
//if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
|
||||
}
|
||||
}
|
||||
// Sort by key, so _noquery_ is last
|
||||
if (!empty($this->default_values)) {
|
||||
foreach ($this->default_values as $a => $b) {
|
||||
foreach ($b as $c => $d) {
|
||||
|
|
@ -643,13 +644,8 @@ class User extends CommonObject
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user