function _card(&$PDOdb, &$object)
{
    global $langs, $conf, $user, $db;
    llxHeader();
    dol_fiche_head(array(), 'menu', 'Menu');
    $formCore = new TFormCore('auto', 'formMenu', 'post');
    echo $formCore->hidden('action', 'save');
    echo $formCore->hidden('id', $object->getId());
    $TQuery = array('0' => '----') + TQuery::getQueries($PDOdb);
    $TDashBoard = array('0' => '----') + TQDashBoard::getDashboard($PDOdb, '', 0, true);
    $tbs = new TTemplateTBS();
    echo $tbs->render('tpl/menu.html', array(), array('menu' => array('type_menu' => $formCore->combo('', 'type_menu', $object->TTypeMenu, $object->type_menu), 'tab_object' => $formCore->combo('', 'tab_object', $object->TTabObject, $object->tab_object), 'mainmenu' => $formCore->combo('', 'mainmenu', TQueryMenu::getMenu($PDOdb, 'main'), $object->mainmenu), 'leftmenu' => $formCore->combo('', 'leftmenu', TQueryMenu::getMenu($PDOdb, 'left'), $object->leftmenu), 'fk_query' => $formCore->combo('', 'fk_query', $TQuery, $object->fk_query), 'fk_dashboard' => $formCore->combo('', 'fk_dashboard', $TDashBoard, $object->fk_dashboard), 'title' => $formCore->texte('', 'title', $object->title, 80, 255), 'perms' => $formCore->texte('', 'perms', $object->perms, 80, 255)), 'view' => array('langs' => $langs, 'buttons' => $formCore->btsubmit($langs->trans('Delete'), 'bt_delete', '', 'butActionDelete') . '   ' . $formCore->btsubmit($langs->trans('Save'), 'bt_save'))));
    $formCore->end();
    dol_fiche_end();
    llxFooter();
}
function _card(&$PDOdb, &$object)
{
    global $langs, $conf, $user, $db;
    if (empty($user->rights->query->bdd->use_other_db)) {
        return '';
    }
    llxHeader();
    dol_fiche_head(array(), 'bdd', 'BDD');
    $tbs = new TTemplateTBS();
    $object->connect();
    $formCore = new TFormCore('auto', 'formBDD', 'post');
    echo $formCore->hidden('action', 'save');
    echo $formCore->hidden('id', $object->getId());
    echo $tbs->render('tpl/bdd.html', array(), array('object' => array('host' => $formCore->texte('', 'host', $object->host, 30, 128), 'db_name' => $formCore->texte('', 'db_name', $object->db_name, 30, 128), 'login' => $formCore->texte('', 'login', $object->login, 30, 128), 'password' => $formCore->texte('', 'password', $object->password, 30, 128), 'port' => $formCore->texte('', 'port', $object->port, 5, 5), 'charset' => $formCore->texte('', 'charset', $object->charset, 10, 128), 'db_type' => $formCore->combo('', 'db_type', $object->TDBType, $object->db_type)), 'view' => array('langs' => $langs, 'buttons' => $formCore->btsubmit($langs->trans('Delete'), 'bt_delete', '', 'butActionDelete') . '   ' . $formCore->btsubmit($langs->trans('Save'), 'bt_save'))));
    $formCore->end();
    dol_fiche_end();
    llxFooter();
}
 private function setSearch(&$TEntete, &$TParam)
 {
     global $langs;
     if (empty($TParam['search'])) {
         return array();
     }
     $TSearch = array();
     $form = new TFormCore();
     $nb_search_in_bar = 0;
     if (!empty($TParam['search'])) {
         foreach ($TEntete as $key => $libelle) {
             // init
             if (empty($TSearch[$key])) {
                 $TSearch[$key] = '';
             }
         }
     }
     foreach ($TParam['search'] as $key => $param_search) {
         $value = isset($_REQUEST['TListTBS'][$this->id]['search'][$key]) ? $_REQUEST['TListTBS'][$this->id]['search'][$key] : '';
         $typeRecherche = is_array($param_search) && isset($param_search['recherche']) ? $param_search['recherche'] : $param_search;
         if (is_array($typeRecherche)) {
             $typeRecherche = array('' => ' ') + $typeRecherche;
             $fsearch = $form->combo('', 'TListTBS[' . $this->id . '][search][' . $key . ']', $typeRecherche, $value);
         } else {
             if ($typeRecherche === 'calendar') {
                 $fsearch = $form->calendrier('', 'TListTBS[' . $this->id . '][search][' . $key . ']', $value, 10, 10);
             } else {
                 if ($typeRecherche === 'calendars') {
                     $fsearch = $form->calendrier('', 'TListTBS[' . $this->id . '][search][' . $key . '][deb]', isset($value['deb']) ? $value['deb'] : '', 10, 10) . ' ' . $form->calendrier('', 'TListTBS[' . $this->id . '][search][' . $key . '][fin]', isset($value['fin']) ? $value['fin'] : '', 10, 10);
                 } else {
                     if (is_string($typeRecherche)) {
                         $fsearch = $TParam['search'][$key];
                     } else {
                         $fsearch = $form->texte('', 'TListTBS[' . $this->id . '][search][' . $key . ']', $value, 15, 255);
                     }
                 }
             }
         }
         if (!empty($TEntete[$key]) || $TParam['type'] == 'chart') {
             $TSearch[$key] = $fsearch;
             $nb_search_in_bar++;
         } else {
             $libelle = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key;
             $TParam['liste']['head_search'] .= '<div>' . $libelle . ' ' . $fsearch . '</div>';
         }
     }
     $search_button = ' <a href="#" onclick="TListTBS_submitSearch(this);" class="list-search-link">' . $TParam['liste']['picto_search'] . '</a>';
     if (!empty($TParam['liste']['head_search'])) {
         $TParam['liste']['head_search'] .= '<div align="right">' . $langs->trans('Search') . ' ' . $search_button . '</div>';
     }
     if ($nb_search_in_bar > 0) {
         end($TSearch);
         list($key, $v) = each($TSearch);
         $TSearch[$key] .= $search_button;
     } else {
         $TSearch = array();
     }
     return $TSearch;
 }
Example #4
0
function _fiche(&$PDOdb, &$hero, $action = 'view')
{
    global $db;
    // création du template
    $form = new TFormCore($_SERVER['PHP_SELF'], 'form', 'POST');
    //affiche un formulaire qui définit les actions
    print $form->hidden('action', 'save');
    print $form->hidden('id', $hero->getId());
    //définit le type d'action du formulaire en fonction de la variable $action récupérée par le GETPOST
    $form->Set_typeaff($action);
    //instanciationb de l'objet template
    $TBS = new TTemplateTBS();
    $buttons = '';
    //si l'action passée en paramètre est à view :
    //on affiche les boutons modifier et supprimer
    if ($action == 'view') {
        //si l'id du héro est égal à 1 :
        //on ne peut qu'ajouter un héro (on ne peut pas supprimer un héro inexistant)
        if ($hero->getId() > 0) {
            $buttons .= "<input type=\"button\" id=\"action-delete\" value=\"Supprimer\" name=\"cancel\" class=\"butActionDelete\" onclick=\"if(confirm('Supprimer ce hero ?'))document.location.href='?action=delete&id=" . $hero->rowid . "'\" />";
        }
        $buttons .= '<a class="butAction" href="?action=edit&id=' . $hero->getId() . '">Modifier</a>';
    } else {
        $buttons .= $form->btsubmit('Valider', 'save');
    }
    /*$btSave = $form->btsubmit('Valider', 'save');
        $btCancel = $form->btsubmit('Annuler', 'cancel');
    	
    	$btDelete = ;
    	*/
    $THero = $hero->get_tab();
    //création de la zone de texte (tirée du template) qui permet d'ajouter le ,nom du héro
    $THero['name'] = $form->texte('', 'name', $hero->name, 30, 255);
    //création de la zone de texte (tirée du template) qui permet d'ajouter la description
    $THero['description'] = $form->zonetexte('', 'description', $hero->description, 80, 5);
    //récupération des pouvoirs dans TPower (tableau de pouvoirs)
    $TPower = $hero->getPower();
    $THero['powers'] = '';
    if (empty($TPower) && $action == 'view') {
        $THero['powers'] .= 'pas de chocolat';
    } else {
        foreach ($TPower as $idp => $pName) {
            if (!empty($THero['powers'])) {
                $THero['powers'] .= ', ';
            }
            $THero['powers'] .= $pName;
            if ($action == 'edit') {
                $THero['powers'] .= ' <a href="?action=delete-power&id=' . $hero->getId() . '&idPower=' . $idp . '">X</a>';
            }
        }
    }
    if ($action == 'edit') {
        $THero['powers'] .= $form->texte(' - Nouveau pouvoir', 'power', '', 30);
    }
    print $TBS->render('./tpl/hero.tpl.php', array(), array('hero' => $THero, 'view' => array('mode' => $mode), 'buttons' => array('buttons' => $buttons)));
    $form->end_form();
}
function fiche_preview(&$object, &$TData)
{
    global $langs, $user, $db, $conf;
    //var_dump($_REQUEST);exit;
    $origin = GETPOST('origin');
    $head = null;
    if ($object->element == 'propal') {
        $head = propal_prepare_head($object);
    } else {
        $head = commande_prepare_head($object);
    }
    if (empty($user->rights->importdevis->myactions)) {
        accessforbidden();
        exit;
    }
    $form = new Form($db);
    llxHeader();
    $title = $langs->trans('Import');
    if ($origin == 'propal') {
        dol_fiche_head($head, 'importdevis', $title, 0, 'propal');
    } else {
        dol_fiche_head($head, 'importdevis', $title, 0, 'commande');
    }
    ?>
		<style type="text/css">
			#table_before_import tr.title_line td.for_line > * {
				display:none;
			}
			
			#table_before_import tr.line_line td.for_title > * {
				display:none;
			}
			
			.for_line select{
				white-space:normal;
				width:300px;
			}
			.ui-dialog {
			    overflow: visible !important;  /* or 'visible' whatever */
			}
		</style>
		
		<script type="text/javascript">
			$(function() {
				var old_type;
				
				$('#to_parse .type select').unbind().click(function() { old_type = $(this).val(); }).change(function() {
					switchClass($(this));
				});
				
				$( "#pop-edit-product-link" ).dialog({
			      modal: true,
			      autoOpen: false,
			      title:"Lier un produit à cette ligne",
			      buttons: {
			        "Lier ce produit": function() {
			        	
			          var fk_product = $('#fk_product_to_link').val() ;
			          var k = $(this).attr('k');	
			          $input = $('tr[k='+k+'] input[rel=fk_product]');
			         //console.log($input);
			         
			          $.ajax({
			          	url:"<?php 
    echo dol_buildpath('/product/ajax/products.php', 1);
    ?>
?action=fetch&id="+fk_product
			          	,dataType:'json'
			          }).done(function(product) {
			          	
			          	$('span[rel="ref-product"][k='+k+']').html(product.ref);
			          	$input.val(fk_product);
			          	console.log(product);
			          	
			          });
			        		
			          $( this ).dialog( "close" );
			        }
			      }
			    });
				
				function switchClass(element)
				{
					var type_value = $(element).val();
	
					if (type_value == 'title') 
					{
						$(element).parent().parent().addClass('liste_titre title_line');
						$(element).parent().parent().removeClass('line_line');
					}
					else 
					{
						$(element).parent().parent().addClass('line_line');
						$(element).parent().parent().removeClass('liste_titre title_line');
						
						if (old_type == 'title' && type_value == 'line')
						{
							while (element.length > 0)
							{
								element = $(element).parent().parent().next().find('td.type').children('select');
								
								if (element.val() == 'title') break;
								
								element.children('option[value=nomenclature]').attr('selected', true);
							}
							
						}
					}
				}
			});
			
			var imp_is_all_check = true;
			function checkAndUncheckAllImport()
			{
				if (imp_is_all_check)
				{
					imp_is_all_check = false;
					$("#to_parse tr .check_imp").attr('checked', false).prop('checked', false);
				}
				else
				{
					imp_is_all_check = true;
					$("#to_parse tr .check_imp").attr('checked', true).prop('checked', true);
				}
			}
			
			function edit_product_link(k) {
				$div = $('#pop-edit-product-link');
				$div.attr('k', k);
				
				$div.dialog('open');
			}
			
		</script>
		<div id="pop-edit-product-link" class="ui-dialog"  >
			<?php 
    $form->select_produits('', 'fk_product_to_link');
    ?>
		</div>
		<table id="table_before_import" width="100%" class="border">
			<tr>
				<td width="25%"><?php 
    echo $langs->trans('Ref');
    ?>
</td>
				<td colspan="3"><div style="vertical-align: middle"><div class="inline-block floatleft refid"><?php 
    echo $object->ref;
    ?>
</div></div></td>
			</tr>
			<tr>
				<td><?php 
    echo $langs->trans('Company');
    ?>
</td>MO-1
				<td colspan="3"><?php 
    echo $object->thirdparty->getNomUrl(1);
    ?>
</td>
			</tr>
			<tr>
				<td colspan="4">
					
						<?php 
    $PDOdb = new TPDOdb();
    $formCore = new TFormCore('auto', 'to_parse', 'post');
    echo $formCore->hidden('action', 'import_data');
    echo $formCore->hidden('id', $object->id);
    echo $formCore->hidden('origin', $origin);
    echo $formCore->hidden('token', $_SESSION['newtoken']);
    echo $formCore->hidden('data', base64_encode(serialize($TData)));
    ?>
							<table class="border" width="100%">
								<tr class="liste_titre">
									<th onclick="javascript:checkAndUncheckAllImport();" style="cursor:pointer;" title="sélectionner/désélectionner tous">Imp.</th>
									<th>Type</th>
									<?php 
    if ($conf->subtotal->enabled) {
        ?>
<th>Niveau</th><?php 
    }
    ?>
									<th>Produit</th>
									<th>Label</th>
									<th>Qté</th>
									<?php 
    if (!empty($conf->global->PRODUCT_USE_UNITS)) {
        ?>
<th>Unité</th><?php 
    }
    ?>
									<th>Prix Achat</th>
									<th>Prix</th>
									<?php 
    if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
        ?>
									<th>Ligne d'origine</th>
									<?php 
    }
    ?>
								</tr>
							<?php 
    if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
        $TPropalDet = array();
        foreach ($object->lines as $line) {
            $label = !empty($line->label) ? $line->label : $line->desc;
            $label .= ' (qté : ' . $line->qty . ', total HT : ' . $line->total_ht . ')';
            $TPropalDet[$line->id] = $label;
        }
    }
    $class = '';
    //var_dump($TData);
    $TWorkstation = TWorkstation::getWorstations($PDOdb);
    foreach ($TData as $k => &$row) {
        //var_dump($row);MO-1
        $workstation = new TWorkstation();
        //var_dump($workstation->loadBy($PDOdb, $row['workstation'], 'code'));
        //var_dump($workstation);exit;
        if (!empty($row['ref'])) {
            $res = $workstation->loadBy($PDOdb, $row['ref'], 'code');
            if ($res > 0) {
                $row['type'] = 'workstation';
                $id_workstation = $workstation->getId();
                //var_dump($workstation);
            }
        }
        $type = $row['type'];
        if ($type == 'title') {
            $class = '';
            print '<tr class="' . $class . ' liste_titre title_line">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            print '<td class="for_title">' . $form->selectarray('TData[' . $k . '][level]', getLevelTitle(), $row['level']) . '</td>';
            print '<td class="for_line">';
            //$form->select_produits(0, 'TData['.$k.'][fk_product]');
            print '</td>';
            print '<td>' . $formCore->texte('', 'TData[' . $k . '][label]', $row['label'], 50, 255) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line"></td>';
            }
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
        } elseif ($type == 'workstation') {
            //var_dump($type);
            $class = '';
            print '<tr class="' . $class . ' workstation_line">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            print '<td></td>';
            print '<td class="for_line">';
            echo $formCore->combo('', 'TData[' . $k . '][fk_workstation]', $TWorkstation, $id_workstation);
            print '</td>';
            print '<td>' . $row['workstation'] . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line"></td>';
            }
            print '<td></td>';
            print '<td></td>';
        } else {
            $class = $class == 'impair' ? 'pair' : 'impair';
            print '<tr class="line_line ' . $class . '" k="' . $k . '">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            if ($conf->subtotal->enabled) {
                print '<td class="for_title">' . $form->selectarray('TData[' . $k . '][level]', getLevelTitle(), $row['level']) . '</td>';
            }
            print '<td class="for_line">';
            if (!empty($row['product_ref'])) {
                $p = new Product($db);
                $p->fetch(null, $row['product_ref']);
                $fk_product = $p->id;
            } else {
                $fk_product = 0;
            }
            print '<span rel="ref-product" k="' . $k . '">' . ($fk_product > 0 ? $p->getNomUrl(1) : 'N/A') . '</span> <a href="javascript:edit_product_link(' . $k . ')">' . img_edit('Changer le produit de destination') . '</a>';
            //$form->select_produits($fk_product, 'TData['.$k.'][fk_product]');
            echo $formCore->hidden('TData[' . $k . '][fk_product]', $fk_product, ' rel="fk_product" ');
            echo $formCore->hidden('TData[' . $k . '][product_ref]', $row['product_ref'], ' rel="product_ref" ');
            print '</td>';
            print '<td>' . $formCore->texte('', 'TData[' . $k . '][label]', $row['label'], 80, 255);
            print '<table>';
            print '<tr>';
            print '<td>Longueur : ' . $formCore->texte('', 'TData[' . $k . '][length]', $row['length'], 15, 255) . '</td>';
            print '<td>Largeur : ' . $formCore->texte('', 'TData[' . $k . '][width]', $row['width'], 15, 255) . '</td>';
            print '<td>Hauteur : ' . $formCore->texte('', 'TData[' . $k . '][height]', $row['height'], 15, 255) . '</td>';
            print '<td>Poids : ' . $formCore->texte('', 'TData[' . $k . '][weight]', $row['weight'], 15, 255) . '</td>';
            print '</tr>';
            print '</table>';
            print '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line">' . $form->selectUnits($row['fk_unit'], 'TData[' . $k . '][fk_unit]', 1) . '</td>';
            }
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][buy_price]', $row['buy_price'], 10, 20) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
        }
        if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
            print '<td class="for_line">' . $form->selectarray('TData[' . $k . '][fk_propaldet]', $TPropalDet, '', 1) . '</td>';
        }
        print '</tr>';
    }
    //exit;
    ?>
							</table>
							<div class="tabsAction">
								<?php 
    echo $langs->trans('DeleteLinesBeforeImport');
    ?>
 <input id="delete_lines_before_import" name="delete_lines_before_import" type="checkbox" value="1" />
								<input class="button" type="submit" value="<?php 
    echo $langs->trans('Import');
    ?>
" />
							</div>
							<?php 
    $formCore->end();
    ?>
				</td>
			</tr>
		</table>
	<?php 
    dol_fiche_end();
    llxFooter();
}
function _create(&$PDOdb, &$db, &$user, &$conf, &$langs, $df = false, $ds = false, $de = false, $amount = 0, $label = '')
{
    unset($_SESSION['SENDTOINVOICETOADHERENT_ERRORS']);
    _list($PDOdb, $db, $user, $conf, $langs, 0);
    if (!$user->rights->sendinvoicetoadherent->create) {
        accessforbidden();
    } else {
        $form = new TFormCore();
        print_fiche_titre($langs->trans("sendinvoicetoadherentTitleCreate"));
        echo '<script type="text/javascript">
			$(function() {
				displayDateCotisation();
			});
			
			function displayDateCotisation(obj) {
				if ($(obj).attr("checked") == "checked") {
					$(".cotisation_create").show()
				} else {
					$(".cotisation_create").hide()
				}
			}
		</script>';
        echo '<form style="padding-top:15px;" name="formsoc" action="' . $_SERVER["PHP_SELF"] . '" method="post" enctype="multipart/form-data">';
        echo '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
        echo '<input type="hidden" name="action" value="createConfirm">';
        echo '<table class="border" width="100%">';
        $date_fac = $df === false ? date('d/m/Y') : $df;
        $date_start = $ds === false ? date('d/m/Y') : $ds;
        $date_end = $de === false ? date('d/m/Y', strtotime('+1 year -1 day')) : $de;
        $label = empty($label) ? $langs->trans("Subscription") . ' ' . ($ds ? substr($date_start, -4, 4) : dol_print_date(time(), '%Y')) : $label;
        echo '<tr><td width="20%" class="fieldrequired">' . $langs->trans("sendinvoicetoadherentDateFacture") . '</td><td width="80%">' . $form->calendrier('', 'date_fac', $date_fac) . '</td></tr>';
        echo '<tr><td width="20%">' . $langs->trans("sendinvoicetoadherentCreateCotisation") . '</td><td width="80%"><input type="checkbox" name="create_cotisation" value="1" onclick="javascript:displayDateCotisation(this);" /></td></tr>';
        echo '<tr class="cotisation_create" style="display:none;"><td width="20%" class="fieldrequired">' . $langs->trans("sendinvoicetoadherentDateStartAdhesion") . '</td><td width="80%">' . $form->calendrier('', 'date_start', $date_start) . '</td></tr>';
        echo '<tr class="cotisation_create" style="display:none;"><td width="20%">' . $langs->trans("sendinvoicetoadherentDateEndAdhesion") . '</td><td width="80%">' . $form->calendrier('', 'date_end', $date_end) . '</td></tr>';
        echo '<tr class="cotisation_create" style="display:none;"><td width="20%" class="fieldrequired">' . $langs->trans("sendinvoicetoadherentAmountAdhesion") . '</td><td width="80%">' . $form->texte('', 'amount_cotisation', $amount, 6, 15) . ' ' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
        echo '<tr class="cotisation_create" style="display:none;"><td width="20%">' . $langs->trans("sendinvoicetoadherentLabelAdhesion") . '</td><td width="80%">' . $form->texte('', 'label', $label, 32, 255) . '</td></tr>';
        echo '</table>';
        if ($user->rights->sendinvoicetoadherent->create) {
            echo '<br /><center>';
            echo '<input type="submit" class="button" value="' . $langs->trans('sendinvoicetoadherentActionCreateConfirm') . '" />&nbsp;&nbsp;&nbsp;&nbsp;';
            echo '<a href="' . dol_buildpath('/sendinvoicetoadherent/sendinvoicetoadherent.php?action=list', 2) . '" class="button" style="text-decoration:none;font-weight:normal;cusor:pointer;height:15px;padding-top:5px;">' . $langs->trans('Cancel') . '</a>';
            echo '</center>';
        }
        echo '</form>';
    }
    $PDOdb->close();
    llxFooter('');
}
$formCore->end();
// Setup page goes here
$var = false;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Parameters") . '</td>' . "\n";
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="100">' . $langs->trans("Value") . '</td>' . "\n";
// Example with a yes / no select
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("setFACTOR_LIMIT_DEPOT") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="set_FACTOR_LIMIT_DEPOT">';
print $formCore->texte('', "FACTOR_LIMIT_DEPOT", $conf->global->FACTOR_LIMIT_DEPOT, 3);
print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
print '</form>';
print '</td></tr>';
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("FACTOR_DO_NOT_UPDATE_NOTE_ON_PROPAL") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print ajax_constantonoff('FACTOR_DO_NOT_UPDATE_NOTE_ON_PROPAL');
print '</td></tr>';
print '</table>';
llxFooter();
$db->close();
print '</td></tr>';
$form = new TFormCore();
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Réception commande fournisseur") . '</td>' . "\n";
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="100">' . $langs->trans("Value") . '</td>' . "\n";
print '<tr>';
// Champ supplémentaire contenant le code comptable produit pour les ventes CEE
$var = !$var;
$form = new TFormCore($_SERVER["PHP_SELF"], 'const_dluo_by_default');
print $form->hidden('action', 'setconst');
print $form->hidden('const', 'DISPATCH_DLUO_BY_DEFAULT');
print '<tr ' . $bc[$var] . '><td>';
print $langs->trans("DispatchDLUOByDefault");
print '</td><td align="right">';
print $form->texte('', 'DISPATCH_DLUO_BY_DEFAULT', $conf->global->DISPATCH_DLUO_BY_DEFAULT, 30, 255);
print '</td><td align="center">';
print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '" />';
print "</td></tr>\n";
$form->end();
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("DISPATCH_UPDATE_ORDER_PRICE_ON_RECEPTION") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="300">';
print ajax_constantonoff("DISPATCH_UPDATE_ORDER_PRICE_ON_RECEPTION");
print '</td></tr>';
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("DISPATCH_CREATE_SUPPLIER_PRICE") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
function _fiche(&$PDOdb, &$idea, $mode = 'view', $editValue = false)
{
    global $db, $langs, $user;
    llxHeader('', $langs->trans('IdeaboxAddItem'), '', '');
    /******/
    $TBS = new TTemplateTBS();
    $TBS->TBS->protect = false;
    $TBS->TBS->noerr = true;
    $form = new TFormCore($_SERVER['PHP_SELF'], 'form', 'POST');
    $form->Set_typeaff($mode);
    echo $form->hidden('id', $idea->getId());
    echo $form->hidden('action', 'save');
    $TIdeaboxItem = _fiche_ligne_ideabox_item($PDOdb, $idea->getId(), $mode);
    $formDoli = new Form($db);
    print $TBS->render('tpl/ideabox.tpl.php', array('TIdeaboxItem' => $TIdeaboxItem), array('TIdeabox' => array('id' => (int) $idea->getId(), 'label' => $form->texte('', 'label', $idea->label, 80, 150, '', '', 'à saisir'), 'usergroup' => $mode == 'view' ? $idea->getNameUserGroup($db) : $formDoli->select_dolgroups($idea->fk_usergroup, 'fk_usergroup', 1)), 'view' => array('type' => 'showficheideabox', 'mode' => $mode, 'user_right' => $user->rights->ideabox->create, 'url' => dol_buildpath('/ideabox/ideabox.php', 2))));
    $form->end();
    llxFooter();
}
print '</form>';
print '</td></tr>';
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("set_ABRICOT_CONVERTPDF_CMD") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300" style="white-space:nowrap;">';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="set_ABRICOT_CONVERTPDF_CMD">';
$formCore = new TFormCore();
print $formCore->texte('', 'ABRICOT_CONVERTPDF_CMD', empty($conf->global->ABRICOT_CONVERTPDF_CMD) ? '' : $conf->global->ABRICOT_CONVERTPDF_CMD, 80, 255, ' placeholder="libreoffice --invisible --norestore --headless --convert-to pdf --outdir " ');
print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
print '</form>';
print '</td></tr>';
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . $langs->trans("set_ABRICOT_NB_MAX_RESULT_SQL") . '</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300" style="white-space:nowrap;">';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="set_ABRICOT_NB_MAX_RESULT_SQL">';
$formCore = new TFormCore();
print $formCore->texte('', 'ABRICOT_NB_MAX_RESULT_SQL', empty($conf->global->ABRICOT_NB_MAX_RESULT_SQL) ? 2000 : $conf->global->ABRICOT_NB_MAX_RESULT_SQL, 10, 50);
print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
print '</form>';
print '</td></tr>';
print '</table>';
llxFooter();
$db->close();
function fiche(&$remise, $type, $mode)
{
    global $conf, $langs, $db;
    $page_name = "RemiseSetup";
    llxHeader('', $langs->trans($page_name));
    $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
    print_fiche_titre($langs->trans($page_name), $linkback);
    // Configuration header
    $head = remiseAdminPrepareHead();
    dol_fiche_head($head, $type, $page_name, 0, "remise@remise");
    $form = new TFormCore('auto', 'form1', 'post');
    $form->Set_typeaff($mode);
    echo $form->hidden('type', $type);
    echo $form->hidden('id', $remise->getId());
    echo $form->hidden('action', 'save');
    $f = new Form($db);
    ?>
	<table class="border" width="100%">
		<tr>
			<td  width="20%"><?php 
    echo $langs->trans('Palier');
    ?>
</td><td><?php 
    echo $form->texte('', 'palier', $remise->palier, 10, 255);
    ?>
</td>
		</tr>
		<tr>
			<td><?php 
    echo $langs->trans('Remise');
    ?>
</td><td><?php 
    echo $form->texte('', 'remise', $remise->remise, 10, 255);
    ?>
</td>
		</tr>
		<tr>
			<td><?php 
    echo $langs->trans('Zip');
    ?>
</td><td><?php 
    echo $form->texte('', 'zip', $remise->zip, 5, 255);
    ?>
</td>
		</tr>
		<tr>
			<td><?php 
    echo $langs->trans('ShipmentMode');
    ?>
</td><td>
				<?php 
    if ((double) DOL_VERSION >= 3.7) {
        $f->selectShippingMethod($remise->fk_shipment_mode, 'fk_shipment_mode', '', 1);
    } else {
        $query = "SELECT rowid, code, libelle";
        $query .= " FROM " . MAIN_DB_PREFIX . "c_shipment_mode";
        $query .= " WHERE active = 1";
        $query .= " ORDER BY libelle ASC";
        $resql = $db->query($query);
        print '<select id="fk_shipment_mode" class="flat selectshippingmethod" name="fk_shipment_mode"' . ($moreattrib ? ' ' . $moreattrib : '') . '>';
        print '<option value="">';
        print '</option>';
        while ($res = $db->fetch_object($resql)) {
            $selected = '';
            if ($remise->fk_shipment_mode == $res->rowid) {
                $selected = 'selected="selected"';
            }
            print '<option value="' . $res->rowid . '" ' . $selected . '>';
            print $langs->trans("SendingMethod" . strtoupper($res->code));
            print '</option>';
        }
        print '</select>';
    }
    ?>
</td>
		</tr>
		
	</table>
	<div class="tabsAction">
		<?php 
    echo $form->btsubmit($langs->trans('Save'), 'bt_save');
    echo $form->btsubmit($langs->trans('Cancel'), 'bt_cancel', '', 'butAction butActionCancel');
    ?>
	</div>
	<?php 
    $form->end();
    dol_fiche_end();
    llxFooter();
}
    $class = $class == 'impair' ? 'pair' : 'impair';
    ?>
        <tr class="<?php 
    echo $class;
    ?>
">
            <td valign="top">
            	
            	<table width="100%">
            		<tr>
            			<td><?php 
    echo $langs->trans('Trigger');
    ?>
</td>
            			<td><?php 
    echo $formCore->texte('', 'TRouting[' . $r->getId() . '][trigger_code]', $r->trigger_code, 25, 50, '', 'trigger_code');
    ?>
</td>
            		</tr>
            		
           			<tr>
            			<td><?php 
    echo $langs->trans('ReverseTrigger');
    ?>
</td>
            			<td><?php 
    echo $formCore->texte('', 'TRouting[' . $r->getId() . '][trigger_code_reverse]', $r->trigger_code_reverse, 25, 50, '', 'trigger_code');
    ?>
</td>
            		</tr>
            		<tr>
    /**
     * Overloading the doActions function : replacing the parent's function with the one below
     *
     * @param   array()         $parameters     Hook metadatas (context, etc...)
     * @param   CommonObject    &$object        The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
     * @param   string          &$action        Current action (if set). Generally create or edit or null
     * @param   HookManager     $hookmanager    Hook manager propagated to allow calling another hook
     * @return  int                             < 0 on error, 0 on success, 1 to replace standard code
     */
    function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
    {
        if (in_array('propalcard', explode(':', $parameters['context'])) || in_array('ordercard', explode(':', $parameters['context']))) {
            global $langs, $conf;
            $langs->load('free2product@free2product');
            global $addButtonToConvertAll;
            $base_new_ref = !empty($conf->global->FREE2PRODUCT_BASE_NEWREF) ? $conf->global->FREE2PRODUCT_BASE_NEWREF : 'FREELINE-';
            if ($addButtonToConvertAll) {
                // On ajoute l'inclusion d'abricot
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/free2product/config.php');
                ?>
				<div class="inline-block divButAction">
					<a class="butAction" href="javascript:convertAllFreeLine();">
						<?php 
                echo $langs->trans('convertAllFreeLine');
                ?>
					</a>
					
				</div>

				<div id="convertAllFreeLine_popup" style="display:none">
					<?php 
                $formCore = new TFormCore();
                ?>
					<table class="border" width="100%">
						<?php 
                foreach ($object->lines as &$line) {
                    if ($line->product_type <= 1 && $line->fk_product == 0) {
                        $lineid = !empty($line->id) ? $line->id : $line->rowid;
                        // compatibilité 3.6
                        $desc = !empty($line->desc) ? $line->desc : $line->description;
                        // compatibilité 3.6
                        echo '<tr>
										<td>' . $formCore->texte('', 'TFreeProduct[' . $line->id . '][ref]', $base_new_ref . $lineid, 15, 255, ' lineid="' . $lineid . '" label="' . htmlentities(addslashes($desc)) . '" qty="' . $line->qty . '" price="' . $line->subprice . '" product_type="' . $line->product_type . '" tva="' . $line->tva_tx . '" ') . '</td>
										<td>' . $line->desc . '</td>
										<td align="right">' . price($line->subprice) . '</td>
										<td align="right">' . price($line->qty) . '</td>
									</tr>';
                    }
                }
                ?>
					</table>
					
				</div>
					<?php 
            }
        }
    }
function fiche(&$dashboard, $action = 'edit', $withHeader = true)
{
    global $langs, $conf, $user, $db;
    $PDOdb = new TPDOdb();
    $form = new TFormCore();
    $cell_height = 200;
    $tab_object = GETPOST('tab_object');
    $table_element = GETPOST('table_element');
    $fk_object = GETPOST('fk_object');
    if (empty($table_element)) {
        if ($tab_object == 'thirdparty') {
            $table_element = 'societe';
        } else {
            if ($tab_object == 'project') {
                $table_element = 'projet';
            } else {
                $table_element = $tab_object;
            }
        }
    }
    if ($withHeader) {
        llxHeader('', 'Query DashBoard', '', '', 0, 0, array('/query/js/dashboard.js', '/query/js/jquery.gridster.min.js'), array('/query/css/dashboard.css', '/query/css/jquery.gridster.min.css'));
        $head = TQueryMenu::getHeadForObject($tab_object, $fk_object);
        dol_fiche_head($head, 'tabQuery' . GETPOST('menuId'), 'Query');
        print_fiche_titre($dashboard->title);
    } else {
        if (GETPOST('for_incusion') > 0) {
            ?>
		<div class="querydashboard">
			<link rel="stylesheet" type="text/css" title="default" href="<?php 
            echo dol_buildpath('/query/css/dashboard.css', 1);
            ?>
">
			<link rel="stylesheet" type="text/css" title="default" href="<?php 
            echo dol_buildpath('/query/css/jquery.gridster.min.css', 1);
            ?>
">
			<script type="text/javascript" src="<?php 
            echo dol_buildpath('/query/js/dashboard.js', 1);
            ?>
"></script>
			<script type="text/javascript" src="<?php 
            echo dol_buildpath('/query/js/jquery.gridster.min.js', 1);
            ?>
"></script>

		<?php 
        } else {
            ?>
<html>
			<head>
				<meta charset="UTF-8">
				<link rel="stylesheet" type="text/css" href="<?php 
            echo dol_buildpath('/theme/eldy/style.css.php?lang=fr_FR&theme=eldy', 1);
            ?>
">
				<link rel="stylesheet" type="text/css" title="default" href="<?php 
            echo dol_buildpath('/query/css/dashboard.css', 1);
            ?>
">
				<link rel="stylesheet" type="text/css" title="default" href="<?php 
            echo dol_buildpath('/query/css/jquery.gridster.min.css', 1);
            ?>
">

				<script type="text/javascript" src="<?php 
            echo dol_buildpath('/includes/jquery/js/jquery.min.js', 1);
            ?>
"></script>
				<script type="text/javascript" src="<?php 
            echo dol_buildpath('/query/js/dashboard.js', 1);
            ?>
"></script>
				<script type="text/javascript" src="<?php 
            echo dol_buildpath('/query/js/jquery.gridster.min.js', 1);
            ?>
"></script>
				<style type="text/css">
					.pagination { display : none; }
					<?php 
            if ((int) GETPOST('allow_gen') != 1) {
                echo '.notInGeneration { display : none; }';
            }
            ?>

					table.liste tr.impair,table.liste tr.pair,table.liste tr.liste_titre,div.titre {
						font-size: 12px;
					}
				</style>
			</head>
		<body >
		<?php 
        }
    }
    ?>
	<script type="text/javascript">
		var MODQUERY_INTERFACE = "<?php 
    echo dol_buildpath('/query/script/interface.php', 1);
    ?>
";
		
		$(document).ready(function(){ //DOM Ready
			
			gridster_width = Math.round($('.gridster').innerWidth() / 5);
			if(gridster_width<50) gridster_width = 240;
			
		    $(".gridster ul").gridster({
		        widget_margins: [10, 10]
		        ,widget_base_dimensions: [gridster_width, <?php 
    echo $cell_height;
    ?>
]
		        ,min_cols:3
		        ,min_rows:5
		        ,serialize_params: function($w, wgd) { 
		        	return { posx: wgd.col, posy: wgd.row, width: wgd.size_x, height: wgd.size_y, k : $w.attr('data-k') } 
		        }
		        <?php 
    if ($action == 'edit') {
        ?>
,resize: {
		            enabled: true
		            ,max_size: [4, 4]
		            ,min_size: [1, 1]
		        }
		        
		       
		       <?php 
    }
    ?>
		    })<?php 
    if ($action == 'view') {
        echo '.data(\'gridster\').disable()';
    }
    ?>
;
		
			var gridster = $(".gridster ul").gridster().data('gridster');
		
			$('#addQuery').click(function() {
				
				var fk_query = $('select[name=fk_query]').val();
				
				$.ajax({
					url: MODQUERY_INTERFACE
					,data: {
						put:'dashboard-query'
						,fk_query : fk_query
						,fk_qdashboard:<?php 
    echo $dashboard->getId();
    ?>
					}
					,dataType:'json'
					
				}).done(function(data) {
					
					var title = $('select[name=fk_query] option:selected').text();
					
					gridster.add_widget('<li data-k="'+data+'">'+title+'</li>',1,1,1,1);	
				});
				
			});
			
			$('#saveDashboard').click(function() {
				
				var $button = $(this);
				
				$button.hide();
				
				$.ajax({
					url: MODQUERY_INTERFACE
					,data: {
						put:'dashboard'
						,id:<?php 
    echo $dashboard->getId();
    ?>
						,title:$('input[name=title]').val()
						,fk_usergroup:$('select[name=fk_usergroup]').val()
						,send_by_mail:$('select[name=send_by_mail]').val()
						,hook:$('select[name=hook]').val()
						,use_as_landing_page:$('select[name=use_as_landing_page]').val()
						,refresh_dashboard:$('input[name=refresh_dashboard]').val()
					}
					
				}).done(function(data) {
				   <?php 
    if ($dashboard->getId() > 0) {
        ?>
$.ajax({
							url: MODQUERY_INTERFACE
							,data: {
								put:'dashboard-query-link'
								,TCoord:gridster.serialize( )
								,fk_qdashboard:<?php 
        echo $dashboard->getId();
        ?>
							}
							,dataType:'json'
							
					  }).done(function(data) {
					  	$button.show();
					  });
						
						<?php 
    } else {
        echo 'document.location.href="?action=view&id="+data;';
    }
    ?>
					  	
		              
				});
				
			});
		
		});
		
		function delTile(idTile) {
			$('li[tile-id='+idTile+']').css('opacity',.5);
			
			$.ajax({
				url: MODQUERY_INTERFACE
				,data: {
					put:'dashboard-query-remove'
					,id : idTile
				}
				,dataType:'json'
				
			}).done(function(data) {
				$('li[tile-id='+idTile+']').toggle();
				//document.location.hre
			});
			
		}
			
	</script>
	<?php 
    if ($action == 'edit') {
        ?>
<div><?php 
        $TQuery = TQuery::getQueries($PDOdb);
        echo $form->texte($langs->trans('Title'), 'title', $dashboard->title, 50, 255);
        $formDoli = new Form($db);
        echo ' - ' . $langs->trans('LimitAccessToThisGroup') . ' : ' . $formDoli->select_dolgroups($dashboard->fk_usergroup, 'fk_usergroup', 1) . '/' . $langs->trans('UseAsLandingPage') . $formDoli->selectarray('use_as_landing_page', array($langs->trans('No'), $langs->trans('Yes')), $dashboard->use_as_landing_page);
        echo $form->combo(' - ' . $langs->trans('SendByMailToThisGroup'), 'send_by_mail', $dashboard->TSendByMail, $dashboard->send_by_mail);
        echo $form->combo(' - ' . $langs->trans('ShowThisInCard'), 'hook', $dashboard->THook, $dashboard->hook);
        echo $form->number('<br />' . $langs->trans('RefreshDashboard'), 'refresh_dashboard', $dashboard->refresh_dashboard, 20, 1, 0);
        ?>
			<a href="#" class="butAction" id="saveDashboard"><?php 
        echo $langs->trans('SaveDashboard');
        ?>
</a>
		</div>
		<?php 
        if ($dashboard->getId() > 0) {
            ?>
		<div>
			<?php 
            $TQuery = TQuery::getQueries($PDOdb);
            echo $form->combo('', 'fk_query', $TQuery, 0);
            ?>
			<a href="#" class="butAction" id="addQuery"><?php 
            echo $langs->trans('AddThisQuery');
            ?>
</a>
		</div>
		
		<?php 
        }
    } else {
        if (!empty($conf->global->QUERY_SHOW_PDF_TRANSFORM)) {
            echo '<div style="text-align:right" class="notInGeneration"><a class="butAction" style=";z-index:999;" href="download-dashboard.php?uid=' . $dashboard->uid . '">' . $langs->trans('Download') . '</a></div>';
        }
    }
    ?>
		
	
	<div class="gridster">
	    <ul>
	    	<?php 
    foreach ($dashboard->TQDashBoardQuery as $k => &$cell) {
        echo '<li tile-id="' . $cell->getId() . '" data-k="' . $k . '" data-row="' . $cell->posy . '" data-col="' . $cell->posx . '" data-sizex="' . $cell->width . '" data-sizey="' . $cell->height . '" ' . ($withHeader ? '' : 'style="overflow:hidden;"') . '>';
        if ($action == 'edit') {
            echo '<a style="position:absolute; top:3px; right:3px; z-index:999;" href="javascript:delTile(' . $cell->getId() . ')">' . img_delete('DeleteThisTile') . '</a>';
        } else {
            echo '<a style="position:absolute; top:3px; right:3px; z-index:999;" href="' . dol_buildpath('/query/query.php?action=run-in&id=' . $cell->query->getId(), 1) . '">' . img_picto($langs->trans('Run'), 'object_cron.png') . '</a>';
        }
        if ($cell->query->type == 'LIST') {
            $cell->query->type = 'SIMPLELIST';
        }
        if (!empty($cell->query)) {
            if (!$withHeader) {
                echo $cell->query->run(false, $cell->height * $cell_height, $table_element, $fk_object, 0);
            } else {
                echo $cell->query->run(false, $cell->height * $cell_height, $table_element, $fk_object);
            }
        }
        echo '</li>';
    }
    ?>
	        
	
	    </ul>
	</div>
	
	<div style="clear:both"></div>

	<?php 
    if ($dashboard->refresh_dashboard > 0 && !$withHeader) {
        echo "<script type=\"text/javascript\">\n";
        echo "   // Automatically refresh\n";
        echo "   setInterval(\"window.location.reload()\"," . 60000 * $dashboard->refresh_dashboard . ");\n";
        echo "</script>\n";
    }
    ?>
	
	<?php 
    if ($withHeader) {
        if ($dashboard->getId() > 0) {
            print dol_buildpath('/query/dashboard.php?action=run&uid=' . $dashboard->uid, 2);
        }
        dol_fiche_end();
        llxFooter();
    } else {
        if (GETPOST('for_incusion') > 0) {
            ?>
</div><?php 
        } else {
            ?>
		</body></html>
		<?php 
        }
    }
}
function _fiche(&$PDOdb, &$dolidacticiel, $action)
{
    global $langs, $db, $user;
    /*
     * View
     */
    $page_name = "dolidacticielSetup";
    llxHeader('', $langs->trans($page_name));
    // Subheader
    $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
    print_fiche_titre($langs->trans($page_name), $linkback);
    // Configuration header
    $head = dolidacticielAdminPrepareHead();
    dol_fiche_head($head, 'create', $langs->trans("Module104640Name"), 0, "dolidacticiel@dolidacticiel");
    $form = new TFormCore($_SERVER['PHP_SELF'], 'formDolidacticiel', 'POST');
    $form->Set_typeaff($action);
    $TBS = new TTemplateTBS();
    $tpl_fiche = "dolidacticiel_admin.tpl.php";
    print $TBS->render('../tpl/' . $tpl_fiche, array(), array('test' => array('id' => $dolidacticiel->getId(), 'rowid' => $form->hidden('rowid', $dolidacticiel->getId()), 'mainmenu' => $form->texte('', 'mainmenu', $dolidacticiel->mainmenu, 50), 'action' => $form->texte('', 'mainmenu', $dolidacticiel->action, 50), 'code' => $form->texte('', 'mainmenu', $dolidacticiel->code, 50), 'prev_code' => $form->texte('', 'mainmenu', $dolidacticiel->prev_code, 50), 'module_name' => $form->texte('', 'mainmenu', $dolidacticiel->module_name, 50), 'cond' => $form->texte('', 'mainmenu', $dolidacticiel->cond, 50), 'title' => $form->texte('', 'mainmenu', $dolidacticiel->title, 50), 'description' => $form->texte('', 'mainmenu', $dolidacticiel->description, 50), 'rights' => $form->texte('', 'mainmenu', $dolidacticiel->rights, 50), 'mainmenutips' => $form->texte('', 'mainmenu', $dolidacticiel->mainmenutips, 50), 'tips' => $form->texte('', 'mainmenu', $dolidacticiel->tips, 50)), 'view' => array('mode' => $action)));
    $form->end();
}
function tabImport(&$TImport, &$expedition)
{
    global $langs, $db;
    $form = new TFormCore();
    $formDoli = new Form($db);
    $formproduct = new FormProduct($db);
    $PDOdb = new TPDOdb();
    print count($TImport) . ' équipement(s) dans votre expédition';
    ?>
	<table width="100%" class="border">
		<tr class="liste_titre">
			<td>Produit</td>
			<td>Numéro de série</td>
			<td>Numéro de Lot</td>
			<td>Quantité</td>
			<td>&nbsp;</td>
		</tr>
		
	<?php 
    $prod = new Product($db);
    $form->Set_typeaff('view');
    if (is_array($TImport)) {
        foreach ($TImport as $k => $line) {
            if ($prod->id == 0 || $line['ref'] != $prod->ref) {
                if (!empty($line['fk_product'])) {
                    $prod->fetch($line['fk_product']);
                } else {
                    $prod->fetch('', $line['ref']);
                }
            }
            $asset = new TAsset();
            $asset->loadBy($PDOdb, $line['numserie'], 'serial_number');
            $asset->load_asset_type($PDOdb);
            $assetLot = new TAssetLot();
            $assetLot->loadBy($PDOdb, $line['lot_number'], 'lot_number');
            $Trowid = TRequeteCore::get_id_from_what_you_want($PDOdb, MAIN_DB_PREFIX . "expeditiondet_asset", array('fk_asset' => $asset->rowid, 'fk_expeditiondet' => $line['fk_expeditiondet']));
            ?>
<tr>
					<td><?php 
            echo $prod->getNomUrl(1) . $form->hidden('TLine[' . $k . '][fk_product]', $prod->id) . $form->hidden('TLine[' . $k . '][ref]', $prod->ref);
            ?>
</td>
					<td><a href="<?php 
            echo dol_buildpath('/asset/fiche.php?id=' . $asset->rowid, 1);
            ?>
"><?php 
            echo $form->texte('', 'TLine[' . $k . '][numserie]', $line['numserie'], 30);
            ?>
</a></td>
					<td><a href="<?php 
            echo dol_buildpath('/asset/fiche_lot.php?id=' . $assetLot->rowid, 1);
            ?>
"><?php 
            echo $form->texte('', 'TLine[' . $k . '][lot_number]', $line['lot_number'], 30);
            ?>
</a></td>
					<td><?php 
            echo $line['quantity'] . " " . ($asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($line['quantity_unit'], $asset->assetType->measuring_units));
            ?>
</td>
					<td>
						<?php 
            if ($expedition->statut != 1) {
                echo '<a href="?action=DELETE_LINE&k=' . $k . '&id=' . $expedition->id . '&rowid=' . $Trowid[0] . '">' . img_delete() . '</a>';
            }
            ?>
					</td>
				</tr>
				
				<?php 
        }
    }
    ?>
			
		
	</table>
	<br>
	<?php 
}
function _fiche(&$PDOdb, &$dispatch)
{
    global $db, $conf, $langs;
    llxHeader();
    $form = new TFormCore('auto', 'asset', 'post');
    echo $form->hidden('action', 'save');
    echo $form->hidden('id', $dispatch->fk_object);
    echo $form->hidden('type_object', $dispatch->type_object);
    $object = _header($dispatch->fk_object, $dispatch->type_object);
    $pListe[0] = "Sélectionnez une ligne";
    foreach ($object->lines as $k => &$line) {
        $label = !empty($line->label) ? $line->label : $line->libelle;
        if (empty($label) && !empty($line->desc)) {
            $label = $line->desc;
        }
        $pListe[$line->id] = $k + 1 . '/ ' . $label;
    }
    print count($dispatch->TDispatchAsset) . ' équipement(s) lié(s)<br />';
    ?>
	<table width="100%" class="border">
		<tr class="liste_titre">
			<?php 
    if (GETPOST('type_object') !== 'ticketsup') {
        print '<td>Ligne concernée</td>';
    }
    ?>
			<td>Equipement</td>
			<?php 
    if (!empty($conf->global->USE_LOT_IN_OF)) {
        ?>
<td>Numéro de Lot</td><?php 
    }
    print '<td>DLUO</td>';
    ?>
			<?php 
    if ($conf->global->clinomadic->enabled) {
        ?>
				<td>IMEI</td>
				<td>Firmware</td>
				<?php 
    }
    ?>
			<td>&nbsp;</td>
		</tr>
		
	<?php 
    foreach ($dispatch->TDispatchAsset as $k => &$da) {
        if ($da->to_delete) {
            continue;
        }
        $class = $class == 'pair' ? 'impair' : 'pair';
        ?>
<tr class="<?php 
        echo $class;
        ?>
">
			<?php 
        if (GETPOST('type_object') !== 'ticketsup') {
            echo '<td>' . $pListe[$da->fk_object] . '</td>';
        }
        ?>
			<td><?php 
        echo $da->asset->getNomUrl(1, 0, 1);
        ?>
</td>
			<td><?php 
        echo $da->asset->lot_number;
        ?>
</td>
			<?php 
        if (!empty($conf->global->USE_LOT_IN_OF)) {
            ?>
<td><?php 
            echo $da->asset->dluo ? dol_print_date($da->asset->dluo) : 'N/A';
            ?>
</td><?php 
        }
        ?>
			
			
			
			<?php 
        if ($conf->global->clinomadic->enabled) {
            ?>
				<td>IMEI</td>
				<td>Firmware</td>
				<?php 
        }
        ?>
			<td><?php 
        if ($object->statut == 0 || $type_object == 'contrat') {
            echo '<a href="?action=delete-line&k=' . $k . '&id=' . $object->id . '&type_object=' . $dispatch->type_object . '">' . img_delete() . '</a>';
        }
        ?>
</td>
		</tr>
		
		<?php 
    }
    $formproduct = new FormProduct($db);
    if ($object->statut == 0 || $type_object == 'contrat') {
        ?>
<tr style="background-color: lightblue;">
			<?php 
        if (GETPOST('type_object') !== 'ticketsup') {
            echo '<td>' . $form->combo('', 'TLine[-1][fk_object]', $pListe, '') . '</td>';
        }
        ?>
			<td><?php 
        echo $form->texte('', 'TLine[-1][serial_number]', '', 30);
        ?>
</td>
			<?php 
        if (!empty($conf->global->USE_LOT_IN_OF)) {
            ?>
<td>&nbsp;</td><?php 
        }
        ?>
			<td>&nbsp;</td>
			<?php 
        if ($conf->global->clinomadic->enabled) {
            ?>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<?php 
        }
        ?>
			<td>Nouveau
			</td>
	</tr><?php 
    }
    ?>
	</table>
	<script type="text/javascript">
		$(document).ready(function() {
			    $( "input[name='TLine[-1][serial_number]']" ).autocomplete({
			      source: "<?php 
    echo dol_buildpath('/dispatch/script/interface.php', 1);
    ?>
?get=serial_number",
			      minLength: 1,
			      select: function( event, ui ) {
			        
			      }
			    });
		});
		
			
		</script>
	<?php 
    echo $form->btsubmit($langs->trans('Save'), 'bt_new');
    dol_fiche_end();
    $form->end();
    llxFooter();
}
function _liste(&$PDOdb)
{
    global $langs, $db, $user, $conf;
    llxHeader('', $langs->trans('ListOFAsset'), '', '');
    //getStandartJS();
    if (isset($_REQUEST['delete_ok'])) {
        ?>
		<br><div class="error"><?php 
        echo $langs->trans('OFAssetDeleted');
        ?>
</div><br>
		<?php 
    }
    $fk_soc = __get('fk_soc', 0, 'integer');
    $fk_product = __get('fk_product', 0, 'integer');
    $fk_commande = __get('fk_commande', 0, 'integer');
    if ($fk_product > 0) {
        dol_include_once('/core/lib/product.lib.php');
        $product = new Product($db);
        $result = $product->fetch($fk_product);
        $head = product_prepare_head($product, $user);
        $titre = $langs->trans("CardProduct" . $product->type);
        $picto = $product->type == 1 ? 'service' : 'product';
        dol_fiche_head($head, 'tabOF2', $titre, 0, $picto);
    } elseif ($fk_commande > 0) {
        dol_include_once("/core/lib/order.lib.php");
        $commande = new Commande($db);
        $result = $commande->fetch($fk_commande);
        $head = commande_prepare_head($commande, $user);
        $titre = $langs->trans("CustomerOrder" . $product->type);
        dol_fiche_head($head, 'tabOF3', $titre, 0, "order");
    }
    $form = new TFormCore();
    $assetOf = new TAssetOF();
    $r = new TSSRenderControler($assetOf);
    $sql = "SELECT ofe.rowid, ofe.numero, ofe.fk_soc, s.nom as client, SUM(ofel.qty) as nb_product_to_make\n\t\t, GROUP_CONCAT(DISTINCT ofel.fk_product SEPARATOR ',') as fk_product, p.label as product, ofe.ordre, ofe.date_lancement , ofe.date_besoin, ofe.fk_commande,ofe.fk_project\n\t\t, ofe.status, ofe.fk_user,ofe.total_estimated_cost, ofe.total_cost, '' AS printTicket\n\t\t  FROM " . MAIN_DB_PREFIX . "assetOf as ofe \n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "assetOf_line ofel ON (ofel.fk_assetOf=ofe.rowid AND ofel.type = 'TO_MAKE')\n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "product p ON (p.rowid = ofel.fk_product)\n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "societe s ON (s.rowid = ofe.fk_soc)\n\t\t  WHERE ofe.entity=" . $conf->entity;
    if ($fk_soc > 0) {
        $sql .= " AND ofe.fk_soc=" . $fk_soc;
    }
    if ($fk_product > 0) {
        $sql .= " AND ofel.fk_product=" . $fk_product;
    }
    if ($fk_commande > 0) {
        $sql .= " AND ofe.fk_commande=" . $fk_commande;
    }
    $sql .= " GROUP BY ofe.rowid ";
    // TODO je me rappelle plus pourquoi j'ai fait cette merde mais ça fait planter le tri, donc à virer.
    /*if($conf->global->ASSET_OF_LIST_BY_ROWID_DESC) $orderBy['ofe.rowid']='DESC';
    	else $orderBy['ofe.date_cre']='DESC';*/
    $TMath = array();
    $THide = array('rowid', 'fk_user', 'fk_product', 'fk_soc');
    if ($fk_commande > 0) {
        $THide[] = 'fk_commande';
    }
    if ($conf->global->OF_NB_TICKET_PER_PAGE == -1) {
        $THide[] = 'printTicket';
    }
    if (empty($user->rights->of->of->price)) {
        $THide[] = 'total_cost';
        $THide[] = 'total_estimated_cost';
    } else {
        $TMath['total_estimated_cost'] = 'sum';
        $TMath['total_cost'] = 'sum';
    }
    if (!empty($fk_product)) {
        $TMath['nb_product_to_make'] = 'sum';
    }
    $form = new TFormCore($_SERVER['PHP_SELF'], 'form', 'GET');
    echo $form->hidden('action', '');
    if ($fk_commande > 0) {
        echo $form->hidden('fk_commande', $fk_commande);
    }
    if ($fk_product > 0) {
        echo $form->hidden('fk_product', $fk_product);
    }
    // permet de garder le filtre produit quand on est sur l'onglet OF d'une fiche produit
    $r->liste($PDOdb, $sql, array('limit' => array('nbLine' => $conf->liste_limit), 'orderBy' => $orderBy, 'subQuery' => array(), 'link' => array('Utilisateur en charge' => '<a href="' . dol_buildpath('/user/card.php?id=@fk_user@', 2) . '">' . img_picto('', 'object_user.png', '', 0) . ' @val@</a>', 'numero' => '<a href="' . dol_buildpath('/of/fiche_of.php?id=@rowid@"', 2) . '>' . img_picto('', 'object_list.png', '', 0) . ' @val@</a>', 'printTicket' => '<input style=width:40px;"" type="number" value="' . (int) $conf->global->OF_NB_TICKET_PER_PAGE . '" name="printTicket[@rowid@]" min="0" />'), 'translate' => array(), 'hide' => $THide, 'type' => array('date_lancement' => 'date', 'date_besoin' => 'date', 'total_cost' => 'money', 'total_estimated_cost' => 'money', 'nb_product_to_make' => 'number'), 'math' => $TMath, 'liste' => array('titre' => $langs->trans('ListOFAsset'), 'image' => img_picto('', 'title.png', '', 0), 'picto_precedent' => img_picto('', 'back.png', '', 0), 'picto_suivant' => img_picto('', 'next.png', '', 0), 'noheader' => (int) isset($_REQUEST['fk_soc']) | (int) isset($_REQUEST['fk_product']), 'messageNothing' => "Il n'y a aucun " . $langs->trans('OFAsset') . " à afficher", 'picto_search' => img_picto('', 'search.png', '', 0)), 'title' => array('numero' => 'Numéro', 'fk_commande' => 'Commande client', 'ordre' => 'Priorité', 'date_lancement' => 'Date du lancement', 'date_besoin' => 'Date du besoin', 'status' => 'Status', 'login' => 'Utilisateur en charge', 'product' => 'Produit', 'client' => 'Client', 'nb_product_to_make' => 'Nb produits à fabriquer', 'total_cost' => 'Coût réel', 'total_estimated_cost' => 'Coût prévu', 'printTicket' => 'impression<br />étiquette', 'fk_project' => 'Projet'), 'orderBy' => array('rowid' => 'DESC'), 'eval' => array('ordre' => 'TAssetOF::ordre(@val@)', 'status' => 'TAssetOF::status(@val@)', 'product' => 'get_format_libelle_produit("@fk_product@")', 'client' => 'get_format_libelle_societe(@fk_soc@)', 'fk_commande' => 'get_format_libelle_commande(@fk_commande@)', 'fk_project' => 'get_format_libelle_projet(@fk_project@)'), 'search' => array('numero' => array('recherche' => true, 'table' => 'ofe'), 'date_lancement' => array('recherche' => 'calendars', 'table' => 'ofe'), 'date_besoin' => array('recherche' => 'calendars', 'table' => 'ofe'), 'status' => array('recherche' => TAssetOF::$TStatus, 'table' => 'ofe'))));
    if ($conf->global->OF_NB_TICKET_PER_PAGE != -1) {
        echo '<p align="right"><input class="button" type="button" onclick="$(this).closest(\'form\').find(\'input[name=action]\').val(\'printTicket\');  $(this).closest(\'form\').submit(); " name="print" value="' . $langs->trans('ofPrintTicket') . '" /></p>';
    }
    $form->end();
    // On n'affiche pas le bouton de création d'OF si on est sur la liste OF depuis l'onglet "OF" de la fiche commande
    if ($fk_commande) {
        $commande = new Commande($db);
        $commande->fetch($fk_commande);
        $r2 = new TSSRenderControler($assetOf);
        $sql = "SELECT c.rowid as fk_commandedet, p.rowid as rowid, p.ref as refProd, p.label as nomProd, c.qty as qteCommandee, c.description, c.product_type";
        $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet c LEFT JOIN " . MAIN_DB_PREFIX . "product p";
        $sql .= " ON (c.fk_product = p.rowid)";
        $sql .= " WHERE c.product_type IN (0,9) AND  c.fk_commande = " . $fk_commande;
        $resql = $db->query($sql);
        //var_dump($db);
        $num = $db->num_rows($resql);
        print_barre_liste($langs->trans('ListOrderProducts'), $page, "liste.php", $param, $sortfield, $sortorder, '', $num);
        $i = 0;
        $form = new TFormCore($_SERVER['PHP_SELF'], 'formMakeOk', 'post');
        echo $form->hidden('fk_commande', __get('fk_commande', 0, 'int'));
        echo $form->hidden('action', 'createOFCommande');
        echo $form->hidden('fk_soc', $commande->socid);
        echo $form->hidden('token', $_SESSION['newtoken']);
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre">';
        print_liste_field_titre("#");
        print_liste_field_titre($langs->trans("Ref"), "liste_of.php", "ref", "", $param, '', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Label"), "liste_of.php", "label", "", $param, 'align="left"', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Quantité à produire"), "liste_of.php", "", "", $param, '', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Produits à ajouter à un OF"), "liste_of.php", "", "", $param, '', $sortfield, $sortorder);
        print "</tr>\n";
        $var = 1;
        $bc = array(1 => 'class="pair"', -1 => 'class="impair"');
        while ($prod = $db->fetch_object($resql)) {
            $var = !$var;
            //print "<tr ".$bc[$var].">";
            if ($prod->product_type == 9) {
                print "<tr>";
                print "<td>&nbsp;</td>";
                print "<td colspan=\"4\"><strong>";
                print $prod->description;
                print '</strong></td>';
            } else {
                if (empty($prod->rowid)) {
                    // ligne libre
                    print "<tr>";
                    print "<td>&nbsp;</td>";
                    print "<td colspan=\"4\">";
                    print $prod->description;
                    print '</td>';
                } else {
                    print "<tr " . $bc[$var] . ">";
                    print "<td>" . ($i + 1) . "</td>";
                    print "<td>";
                    $p_static = new Product($db);
                    $p_static->ref = $prod->refProd;
                    $p_static->id = $prod->rowid;
                    print $p_static->getNomUrl(1);
                    print "</td>\n";
                    print '<td>';
                    print $prod->nomProd;
                    print '</td>';
                    print "<td>";
                    print $form->texte('', 'TQuantites[' . $prod->fk_commandedet . ']', $prod->qteCommandee, 3, 255);
                    print "</td>";
                    print "<td>" . $form->checkbox1('', 'TProducts[' . $prod->fk_commandedet . '][' . (int) $prod->rowid . ']', false, true, '', 'checkOF');
                    print "</td>";
                    print "</tr>\n";
                    $i++;
                }
            }
        }
        print '<tr class="liste_titre">';
        echo '<th class="liste_titre" colspan="2">&nbsp;</th><th class="liste_titre">&nbsp;</th><th class="liste_titre">&nbsp;</th>
		<th class="liste_titre"><input type="checkbox" id="checkall" checked="checked" value="1"></th>
		';
        print '</tr>';
        print "</table>";
        ?>
<script type="text/javascript">
			$('input#checkall').change(function() {
				
				$('input.checkOF').prop('checked',$(this).is(':checked'));	
				
			});
			
		</script>
		
		<?php 
        echo '<p align="right">' . $form->btsubmit('Créer OFs', 'subForm') . ' ' . $form->btsubmit('Créer un seul OF', 'subFormAlone') . '</p>';
        $form->end();
        echo '</div>';
        $db->free($resql);
    } else {
        if (!empty($fk_product)) {
            $sql = "SELECT ofe.rowid, ofe.numero, ofe.fk_soc, s.nom as client, SUM(IF(ofel.qty>0,ofel.qty,ofel.qty_needed) ) as nb_product_needed, ofel.fk_product, p.label as product, ofe.ordre, ofe.date_lancement , ofe.date_besoin\n            , ofe.status, ofe.fk_user, ofe.total_cost\n              FROM " . MAIN_DB_PREFIX . "assetOf as ofe \n              LEFT JOIN " . MAIN_DB_PREFIX . "assetOf_line ofel ON (ofel.fk_assetOf=ofe.rowid AND ofel.type = 'NEEDED')\n              LEFT JOIN " . MAIN_DB_PREFIX . "product p ON p.rowid = ofel.fk_product\n              LEFT JOIN " . MAIN_DB_PREFIX . "societe s ON s.rowid = ofe.fk_soc\n              WHERE ofe.entity=" . $conf->entity . " AND ofel.fk_product=" . $fk_product . " AND ofe.status!='CLOSE'";
            $sql .= " GROUP BY ofe.rowid ";
            if ($conf->global->ASSET_OF_LIST_BY_ROWID_DESC) {
                $orderBy['ofe.rowid'] = 'DESC';
            } else {
                $orderBy['ofe.date_cre'] = 'DESC';
            }
            $TMath = array();
            $THide = array('rowid', 'fk_user', 'fk_product', 'fk_soc');
            if (empty($user->rights->asset->of->price)) {
                $THide[] = 'total_cost';
            } else {
                $TMath['total_cost'] = 'sum';
            }
            $TMath['nb_product_needed'] = 'sum';
            $l = new TListviewTBS('listeofproductneeded');
            echo $langs->trans('ofListProductNeeded');
            echo $l->render($PDOdb, $sql, array('limit' => array('nbLine' => $conf->liste_limit), 'orderBy' => $orderBy, 'subQuery' => array(), 'link' => array('Utilisateur en charge' => '<a href="' . dol_buildpath('/user/card.php?id=@fk_user@', 2) . '">' . img_picto('', 'object_user.png', '', 0) . ' @val@</a>', 'numero' => '<a href="' . dol_buildpath('/of/fiche_of.php?id=@rowid@', 2) . '">' . img_picto('', 'object_list.png', '', 0) . ' @val@</a>', 'product' => '<a href="' . dol_buildpath('/product/card.php?id=@fk_product@', 2) . '">' . img_picto('', 'object_product.png', '', 0) . ' @val@</a>', 'client' => '<a href="' . dol_buildpath('/societe/soc.php?id=@fk_soc@', 2) . '">' . img_picto('', 'object_company.png', '', 0) . ' @val@</a>'), 'translate' => array(), 'hide' => $THide, 'type' => array('date_lancement' => 'date', 'date_besoin' => 'date', 'total_cost' => 'money', 'nb_product_needed' => 'number'), 'math' => $TMath, 'liste' => array('titre' => $langs->trans('ListOFAsset'), 'image' => img_picto('', 'title.png', '', 0), 'picto_precedent' => img_picto('', 'back.png', '', 0), 'picto_suivant' => img_picto('', 'next.png', '', 0), 'noheader' => (int) isset($_REQUEST['fk_soc']) | (int) isset($_REQUEST['fk_product']), 'messa geNothing' => "Il n'y a aucun " . $langs->trans('OFAsset') . " à afficher", 'picto_search' => img_picto('', 'search.png', '', 0)), 'title' => array('numero' => 'Numéro', 'ordre' => 'Priorité', 'date_lancement' => 'Date du lancement', 'date_besoin' => 'Date du besoin', 'status' => 'Status', 'login' => 'Utilisateur en charge', 'product' => 'Produit', 'client' => 'Client', 'nb_product_needed' => 'Nb produits nécessaire', 'total_cost' => 'Coût'), 'eval' => array('ordre' => 'TAssetOF::ordre(@val@)', 'status' => 'TAssetOF::status(@val@)', 'product' => 'get_format_libelle_produit(@fk_product@)', 'client' => 'get_format_libelle_societe(@fk_soc@)')));
        }
        echo '<div class="tabsAction">';
        echo '<a id="bt_createOf" class="butAction" href="fiche_of.php?action=new' . (!empty($fk_product) ? '&fk_product=' . $fk_product : '') . '">' . $langs->trans('CreateOFAsset') . '</a>';
        if ($conf->nomenclature->enabled && !empty($fk_product)) {
            dol_include_once('/core/class/html.form.class.php');
            dol_include_once('/asset/lib/asset.lib.php');
            dol_include_once('/nomenclature/class/nomenclature.class.php');
            $doliForm = new Form($db);
            echo $doliForm->selectarray('fk_nomenclature', TNomenclature::get($PDOdb, $fk_product, true));
            echo '<script type="text/javascript">

				    var url_create_of = $("#bt_createOf").attr("href");
	                   	    $("#bt_createOf").attr("href","#");  
                        
					$("#bt_createOf").click(function() {
						var fk_nomenclature = $("select[name=fk_nomenclature]").val();
						var href = url_create_of + "&fk_nomenclature=" + fk_nomenclature;
						$(this).attr("href", href);
					});
			</script>';
        }
        echo '</div>';
    }
    $PDOdb->close();
    llxFooter('');
}
function _fiche(&$ATMdb, &$control, $mode = 'view', $editValue = false)
{
    global $db, $langs;
    llxHeader('', $langs->trans('AssetAddControl'), '', '');
    $TBS = new TTemplateTBS();
    $form = new TFormCore();
    $form->Set_typeaff($mode);
    $TForm = array('id' => $control->getId(), 'libelle' => $form->texte('', 'libelle', $control->libelle, 50, 255), 'type' => $form->combo('', 'type', TAssetControl::$TType, $control->type), 'question' => $form->texte('', 'question', $control->question, 120, 255));
    $TFormVal = _fiche_value($ATMdb, $editValue);
    $TVal = _liste_valeur($ATMdb, $control->getId(), $control->type);
    print $TBS->render('./tpl/control.tpl.php', array('TVal' => $TVal), array('co' => $TForm, 'FormVal' => $TFormVal, 'view' => array('mode' => $mode, 'editValue' => $editValue, 'type' => $control->type, 'url' => dol_buildpath('/of/control.php', 1))));
    llxFooter();
}