mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix switch page status. Fix clone page.
This commit is contained in:
parent
ebfdf51ae7
commit
7778bc4b01
|
|
@ -718,10 +718,11 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof
|
|||
* @param string $morecss More CSS
|
||||
* @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on the same page for the same field.
|
||||
* @param int $forcenojs Force the component to work as link post (without javascript) instead of ajax call
|
||||
* @param string $moreparam When $forcenojs=1 then we can add more parameters to the backtopage URL. String must url encoded. Example: 'abc=def&fgh=ijk'
|
||||
* @return string html for button on/off
|
||||
* @see ajax_constantonoff() to update that value of a constant
|
||||
*/
|
||||
function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '', $forcenojs = 0)
|
||||
function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '', $forcenojs = 0, $moreparam = '')
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
|
|
@ -826,8 +827,8 @@ function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input =
|
|||
}
|
||||
|
||||
if (empty($conf->use_javascript_ajax) || $forcenojs) {
|
||||
$out .= '<a id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).'</a>';
|
||||
$out .= '<a id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).'</a>';
|
||||
$out .= '<a id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.($moreparam ? '&'.$moreparam : '')).'">'.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).'</a>';
|
||||
$out .= '<a id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.($moreparam ? '&'.$moreparam : '')).'">'.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).'</a>';
|
||||
} else {
|
||||
$out .= '<span id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).'</span>';
|
||||
$out .= '<span id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).'</span>';
|
||||
|
|
|
|||
|
|
@ -105,16 +105,6 @@ class WebsitePage extends CommonObject
|
|||
*/
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* @var integer|string date_creation
|
||||
*/
|
||||
public $date_creation;
|
||||
|
||||
/**
|
||||
* @var integer|string date_modification
|
||||
*/
|
||||
public $date_modification;
|
||||
|
||||
public $fk_user_creat;
|
||||
public $fk_user_modif;
|
||||
|
||||
|
|
@ -169,7 +159,7 @@ class WebsitePage extends CommonObject
|
|||
|
||||
// BEGIN MODULEBUILDER PROPERTIES
|
||||
/**
|
||||
* @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
* @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int<-2,5>|string,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array<int|string,string>,comment?:string,validate?:int<0,1>}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields = array(
|
||||
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
|
||||
|
|
@ -363,7 +353,7 @@ class WebsitePage extends CommonObject
|
|||
/**
|
||||
* Return array of all web site pages.
|
||||
*
|
||||
* @param string $websiteid Web site
|
||||
* @param string|int $websiteid Web site ID
|
||||
* @param string $sortorder Sort Order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit limit
|
||||
|
|
@ -373,7 +363,7 @@ class WebsitePage extends CommonObject
|
|||
* @param string $filtermode No more used
|
||||
* @return WebSitePage[]|int<-1,-1> int <0 if KO, array of pages if OK
|
||||
*/
|
||||
public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
|
||||
public function fetchAll($websiteid = '', $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
|
||||
{
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
|
|
@ -405,7 +395,9 @@ class WebsitePage extends CommonObject
|
|||
$sql .= " t.object_type,";
|
||||
$sql .= " t.fk_object";
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||
$sql .= ' WHERE t.fk_website = '.((int) $websiteid);
|
||||
if (!empty($websiteid)) {
|
||||
$sql .= ' WHERE t.fk_website = '.((int) $websiteid);
|
||||
}
|
||||
|
||||
// Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
|
||||
if (is_array($filter)) {
|
||||
|
|
@ -438,7 +430,11 @@ class WebsitePage extends CommonObject
|
|||
}
|
||||
}
|
||||
if (count($sqlwhere) > 0) {
|
||||
$sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
|
||||
if (!empty($websiteid)) {
|
||||
$sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
|
||||
} else {
|
||||
$sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
|
||||
}
|
||||
}
|
||||
|
||||
$filter = '';
|
||||
|
|
@ -676,16 +672,17 @@ class WebsitePage extends CommonObject
|
|||
/**
|
||||
* Load an object from its id and create a new one in database
|
||||
*
|
||||
* @param User $user User making the clone
|
||||
* @param int $fromid Id of object to clone
|
||||
* @param string $newref New ref/alias of page
|
||||
* @param string $newlang New language
|
||||
* @param int $istranslation 1=New page is a translation of the cloned page.
|
||||
* @param int $newwebsite 0=Same web site, >0=Id of new website
|
||||
* @param string $newtitle New title
|
||||
* @return mixed New object created, <0 if KO
|
||||
* @param User $user User making the clone
|
||||
* @param int $fromid Id of object to clone
|
||||
* @param string $newref New ref/alias of page
|
||||
* @param string $newlang New language
|
||||
* @param int $istranslation 1=New page is a translation of the cloned page.
|
||||
* @param int $newwebsite 0=Same web site, >0=Id of new website
|
||||
* @param string $newtitle New title
|
||||
* @param Website|null $website Website
|
||||
* @return mixed New object created, <0 if KO
|
||||
*/
|
||||
public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
|
||||
public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '', $website = null)
|
||||
{
|
||||
global $hookmanager, $langs;
|
||||
|
||||
|
|
@ -708,6 +705,19 @@ class WebsitePage extends CommonObject
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ($istranslation) {
|
||||
if (is_null($website)) {
|
||||
$website = new Website($db);
|
||||
}
|
||||
$website->fetch($object->fk_website);
|
||||
|
||||
if ($website->id != $newwebsite) {
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Load source object
|
||||
|
|
@ -727,11 +737,18 @@ class WebsitePage extends CommonObject
|
|||
if (!empty($newlang)) {
|
||||
$object->lang = $newlang;
|
||||
}
|
||||
|
||||
if ($istranslation) {
|
||||
$object->fk_page = $fromid;
|
||||
if ($website->lang == $newlang) {
|
||||
// The new page is into the website language, the parent page will be 0, and we must instead update the source page later.
|
||||
$object->fk_page = 0;
|
||||
} else {
|
||||
$object->fk_page = $fromid;
|
||||
}
|
||||
} else {
|
||||
$object->fk_page = 0;
|
||||
}
|
||||
|
||||
if (!empty($newwebsite)) {
|
||||
$object->fk_website = $newwebsite;
|
||||
}
|
||||
|
|
@ -748,6 +765,19 @@ class WebsitePage extends CommonObject
|
|||
dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
|
||||
}
|
||||
|
||||
if ($istranslation) {
|
||||
if ($website->lang == $newlang) {
|
||||
// We must now update the source page to link to the new page as a translation of.
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."website_page SET fk_page = ".((int) $result)." WHERE rowid = ".((int) $fromid);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if (!$result) {
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($object->context['createfromclone']);
|
||||
|
||||
// End
|
||||
|
|
|
|||
|
|
@ -2248,7 +2248,7 @@ if ($usercanedit && (($action == 'updatesource' || $action == 'updatecontent' ||
|
|||
}
|
||||
|
||||
$objectpage = new WebsitePage($db);
|
||||
$resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'));
|
||||
$resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'), $tmpwebsite);
|
||||
if ($resultpage < 0) {
|
||||
$error++;
|
||||
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
|
||||
|
|
@ -3282,6 +3282,7 @@ if (!GETPOST('hide_websitemenu')) {
|
|||
|
||||
print $out;
|
||||
|
||||
// Button to switch status
|
||||
if (!empty($conf->use_javascript_ajax)) {
|
||||
print '<span class="websiteselection">';
|
||||
//print '<div class="inline-block marginrightonly">';
|
||||
|
|
@ -3293,7 +3294,7 @@ if (!GETPOST('hide_websitemenu')) {
|
|||
print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_on').'</span>';
|
||||
}
|
||||
} else {
|
||||
print ajax_object_onoff($websitepage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block'.(empty($websitepage->id) ? ' opacitymedium disabled' : ''), 'statuswebsitepage', 1);
|
||||
print ajax_object_onoff($websitepage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block'.(empty($websitepage->id) ? ' opacitymedium disabled' : ''), 'statuswebsitepage', 1, 'pageid='.$websitepage->id);
|
||||
}
|
||||
//print '</div>';
|
||||
print '</span>';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user