Works on possibility to change customer when cloning (not stable, disabled)

New: can send extra input in ajax dialog
This commit is contained in:
Regis Houssin 2011-04-24 20:24:50 +00:00
parent 6db7eef7fb
commit 2b5d169575
3 changed files with 47 additions and 16 deletions

View File

@ -710,12 +710,13 @@ class Commande extends CommonObject
/**
* \brief Load an object from its id and create a new one in database
* \param fromid Id of object to clone
* \param invertdetail Reverse sign of amounts for lines
* \return int New id of clone
* Load an object from its id and create a new one in database
* @param fromid Id of object to clone
* @param invertdetail Reverse sign of amounts for lines
* @param socid Id of thirdparty
* @return int New id of clone
*/
function createFromClone($fromid,$invertdetail=0)
function createFromClone($fromid,$invertdetail=0,$socid=0)
{
global $conf,$user,$langs;
@ -734,6 +735,13 @@ class Commande extends CommonObject
// Load source object
$object->fetch($fromid);
$objFrom = $object;
// Change socid if needed
if (! empty($socid) && $socid != $object->socid)
{
$object->socid = $socid;
// TODO clear delivery address, project linked, change product price if multi-prices
}
$object->id=0;
$object->statut=0;

View File

@ -90,13 +90,13 @@ if (! empty($object->hooks))
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{
if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
if ( 1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') )
{
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
}
else
{
$result=$object->createFromClone($id);
$result=$object->createFromClone($id, 0, GETPOST('socid'));
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
@ -1497,7 +1497,8 @@ else
// Create an array for form
$formquestion=array(
//'text' => $langs->trans("ConfirmClone"),
//array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
//array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
//array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $html->select_company(GETPOST('socid'),'socid','(s.client=1 OR s.client=3)'))
);
// Paiement incomplet. On demande si motif = escompte ou autre
$formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
@ -1936,7 +1937,7 @@ else
// Clone
if ($user->rights->commande->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
}
// Cancel order

View File

@ -1986,6 +1986,7 @@ class Form
$more='';
$formconfirm='';
$inputarray=array();
if (empty($height)) $height=170;
@ -1997,15 +1998,16 @@ class Form
{
if ($input['type'] == 'text')
{
$more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
$more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
}
if ($input['type'] == 'password')
{
$more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="password" class="flat" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
$more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="password" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
}
if ($input['type'] == 'select')
{
$more.='<tr><td valign="top">';
$more.='<tr><td valign="top">';
if (! empty($input['label'])) $more.=$input['label'].'</td><td valign="top" colspan="2" align="left">';
$more.=$this->selectarray($input['name'],$input['values'],'',1);
$more.='</td></tr>'."\n";
}
@ -2014,7 +2016,7 @@ class Form
$more.='<tr>';
//$more.='<td valign="top">'.$input['label'].' &nbsp;';
$more.='<td valign="top">'.$input['label'].' </td><td valign="top" align="left">';
$more.='<input type="checkbox" class="flat" name="'.$input['name'].'"';
$more.='<input type="checkbox" class="flat" id="'.$input['name'].'" name="'.$input['name'].'"';
if (! is_bool($input['value']) && $input['value'] != 'false') $more.=' checked="true"';
if (is_bool($input['value']) && $input['value']) $more.=' checked="true"';
if ($input['disabled']) $more.=' disabled="true"';
@ -2032,7 +2034,7 @@ class Form
$more.='<tr>';
if ($i==0) $more.='<td valign="top">'.$input['label'].'</td>';
else $more.='<td>&nbsp;</td>';
$more.='<td valign="top" width="20"><input type="radio" class="flat" name="'.$input['name'].'" value="'.$selkey.'"';
$more.='<td valign="top" width="20"><input type="radio" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$selkey.'"';
if ($input['disabled']) $more.=' disabled="true"';
$more.='></td>';
$more.='<td valign="top" align="left">';
@ -2041,6 +2043,14 @@ class Form
$i++;
}
}
if ($input['type'] == 'other')
{
$more.='<tr><td valign="top">';
if (! empty($input['label'])) $more.=$input['label'].'</td><td valign="top" colspan="2" align="left">';
$more.=$input['value'];
$more.='</td></tr>'."\n";
}
array_push($inputarray,$input['name']);
}
$more.='</table>'."\n";
}
@ -2058,6 +2068,7 @@ class Form
$formconfirm.= '</div>'."\n";
$formconfirm.= '<script type="text/javascript">
var choice=\'ko\';
var $inputarray='.json_encode($inputarray).';
jQuery("#dialog-confirm").dialog({
autoOpen: true,
resizable: false,
@ -2066,7 +2077,18 @@ class Form
modal: true,
closeOnEscape: false,
close: function(event, ui) {
if (choice == \'ok\') location.href=\''.$pageyes.'\';
if (choice == \'ok\') {
var options="";
if ($inputarray.length>0) {
$.each($inputarray, function() {
var inputname = this;
var inputvalue = $("#" + this).val();
options += \'&\' + inputname + \'=\' + inputvalue;
});
//alert( options );
}
location.href=\''.$pageyes.'\' + options;
}
'.($pageno?'if (choice == \'ko\') location.href=\''.$pageno.'\';':'').'
},
buttons: {
@ -2086,7 +2108,7 @@ class Form
}
else
{
$formconfirm.= '<form method="post" action="'.$page.'" class="notoptoleftroright">'."\n";
$formconfirm.= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n";
$formconfirm.= '<input type="hidden" name="action" value="'.$action.'">';
$formconfirm.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";