/**
     * 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 formAddObjectLine($parameters, &$object, &$action, $hookmanager)
    {
        global $db, $langs, $user, $conf, $inputalsopricewithtax;
        $TContext = explode(':', $parameters['context']);
        if (in_array('propalcard', $TContext) || in_array('ordercard', $TContext) || in_array('invoicecard', $TContext)) {
            if ($user->rights->searchproductcategory->user->search) {
                //Charger les liste des projets de type feuille de temps pas encore facturé
                $colspan1 = 4;
                $colspan2 = 4;
                if (!empty($inputalsopricewithtax)) {
                    $colspan1++;
                    $colspan2++;
                }
                if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                    $colspan1++;
                }
                if (!empty($conf->margin->enabled)) {
                    $colspan1++;
                    if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARGIN_RATES)) {
                        $colspan1++;
                    }
                    if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARK_RATES)) {
                        $colspan1++;
                    }
                }
                $langs->load('searchproductcategory@searchproductcategory');
                ?>
<script type="text/javascript">
	        		var spc_object_type = '<?php 
                echo $object->element;
                ?>
';
	        		var spc_object_id = '<?php 
                echo $object->id;
                ?>
';
	        	</script>
				<tr class="liste_titre nodrag nodrop">
					<td colspan="<?php 
                echo $colspan1;
                ?>
"><?php 
                echo $langs->trans('SearchByCategory');
                ?>
</td>
					<td align="right"><?php 
                echo $langs->trans('Qty');
                ?>
</td>
					<td align="center" colspan="<?php 
                echo $colspan2;
                ?>
">&nbsp;<?php 
                if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) {
                    echo $langs->trans('subtotal_title_to_add_under_title');
                }
                ?>
</td>
				</tr>
				<tr class="pair">
					<td colspan="<?php 
                echo $colspan1;
                ?>
">
						<div id="arboresenceCategoryProduct" spc-role="arbo-multiple">
							
						</div>
					</td>
					<td class="nobottom" align="right">
						<input id="qty_spc" type="text" value="1" size="5" class="flat" />
					</td>
					<td valign="middle" align="center" colspan="<?php 
                echo $colspan2;
                ?>
">
						<?php 
                if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) {
                    dol_include_once('/subtotal/class/subtotal.class.php');
                    $TTitle = TSubtotal::getAllTitleFromDocument($object);
                    echo getHtmlSelectTitle($object);
                }
                ?>
						<input id="addline_spc" class="button" type="button" name="addline_timesheet" value="<?php 
                echo $langs->trans('Add');
                ?>
">
					</td>
				</tr>
				
				<?php 
            }
        }
        return 0;
    }
    /**
     * 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 formAddObjectLine($parameters, &$object, &$action, $hookmanager)
    {
        global $db, $langs, $user, $conf, $inputalsopricewithtax;
        $langs->load('contratconcurrent@contratconcurrent');
        $TContext = explode(':', $parameters['context']);
        if (in_array('propalcard', $TContext)) {
            dol_include_once('/core/class/html.form.class.php');
            $form = new Form($db);
            $TContratConcurrent = $this->getTContratConcurrent($object);
            $usemargins = 0;
            if (!empty($conf->margin->enabled) && !empty($object->element)) {
                $usemargins = 1;
            }
            $colspan = 4;
            if (!empty($inputalsopricewithtax)) {
                $colspan++;
            }
            ?>
        	
        	<tr class="liste_titre nodrag nodrop">
        		<td<?php 
            echo !empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : '';
            ?>
><?php 
            echo $langs->trans('ImportContratLine');
            ?>
</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<?php 
            if (!empty($inputalsopricewithtax)) {
                ?>
				<td align="right">&nbsp;</td>
				<?php 
            }
            ?>
				<td align="right">&nbsp;</td>
				<?php 
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                ?>
				<td align="left">&nbsp;</td>
				<?php 
            }
            ?>
				<td align="right">&nbsp;</td>
				<?php 
            if ($object->situation_cycle_ref) {
                print '<td align="right">&nbsp;</td>';
            }
            if (!empty($usemargins)) {
                ?>
					<td align="right">&nbsp;</td>
					<?php 
                if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARGIN_RATES)) {
                    echo '<td align="right">&nbsp;</td>';
                }
                if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARK_RATES)) {
                    echo '<td align="right">&nbsp;</td>';
                }
            }
            ?>
				<td align="center" colspan="<?php 
            echo $colspan;
            ?>
">&nbsp;<?php 
            if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) {
                echo $langs->trans('subtotal_title_to_add_under_title');
            }
            ?>
</td>
			</tr>
			<tr class="pair">
				<script type="text/javascript">
					function checkInputRadioContratConcurrent() 
					{
						$('input#prod_entry_mode_import_line_contrat_concurrent').click();
						$('#select_type option[value="-1"]').attr('selected', true).prop('selected', true);
						$('#idprod').val('');
						$('#search_idprod').val('');
					}
				</script>
				<td>
					<label>
						<input id="prod_entry_mode_import_line_contrat_concurrent" type="radio" value="contrat_line" name="prod_entry_mode">
						<?php 
            echo $langs->trans('add_fk_contrat_line_in_propal');
            ?>
					</label>
					
					<?php 
            $moreparam = 'onchange="checkInputRadioContratConcurrent();" style="min-width:150px;"';
            print Form::selectarray('fk_line_contrat_origin', $TContratConcurrent, '', 1, 0, 0, $moreparam, 0, 0, 0, '', '', 1);
            ?>
				</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<?php 
            if (!empty($inputalsopricewithtax)) {
                ?>
				<td align="right">&nbsp;</td>
				<?php 
            }
            ?>
				<td align="right">&nbsp;</td>
				<?php 
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                ?>
				<td align="left">&nbsp;</td>
				<?php 
            }
            ?>
				<td align="right">&nbsp;</td>
				<?php 
            if ($object->situation_cycle_ref) {
                print '<td align="right">&nbsp;</td>';
            }
            if (!empty($usemargins)) {
                ?>
					<td align="right">&nbsp;</td>
					<?php 
                if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARGIN_RATES)) {
                    echo '<td align="right">&nbsp;</td>';
                }
                if ($user->rights->margins->creer && !empty($conf->global->DISPLAY_MARK_RATES)) {
                    echo '<td align="right">&nbsp;</td>';
                }
            }
            ?>
				<td valign="middle" align="center" colspan="<?php 
            echo $colspan;
            ?>
">
					<?php 
            if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE)) {
                dol_include_once('/subtotal/class/subtotal.class.php');
                $TTitle = TSubtotal::getAllTitleFromDocument($object);
                echo getHtmlSelectTitle($object);
            }
            ?>
					<input type="submit" id="addcontratline" name="addcontratline" value="Ajouter" class="button">
				</td>
			
			</tr>
        	<?php 
        }
    }