/** * Show event of a particular day for a user * * @param string $username Login * @param int $day Day * @param int $month Month * @param int $year Year * @param int $monthshown Current month shown in calendar view * @param string $style Style to use for this day * @param array $eventarray Array of events * @param int $maxprint Nb of actions to show each day on month view (0 means no limit) * @param int $maxnbofchar Nb of characters to show for event line * @param string $newparam Parameters on current URL * @param int $showinfo Add extended information (used by day view) * @param int $minheight Minimum height for each event. 60px by default. * @param boolean $showheader Show header * @param array $colorsbytype Array with colors by type * @param bool $var true or false for alternat style on tr/td * @return void */ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $showheader = false, $colorsbytype = array(), $var = false) { global $db; global $user, $conf, $langs, $hookmanager, $action; global $filter, $filtert, $status, $actioncode; // Filters used into search form global $theme_datacolor; // Array with a list of different we can use (come from theme) global $cachethirdparties, $cachecontacts, $colorindexused; global $begin_h, $end_h; $cases1 = array(); // Color first half hour $cases2 = array(); // Color second half hour $curtime = dol_mktime(0, 0, 0, $month, $day, $year); $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array(); $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day); $nextindextouse = count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ... //if ($username->id && $day==1) var_dump($eventarray); // We are in a particular day for $username, now we scan all events foreach ($eventarray as $daykey => $notused) { $annee = date('Y', $daykey); $mois = date('m', $daykey); $jour = date('d', $daykey); //print $annee.'-'.$mois.'-'.$jour.' '.$year.'-'.$month.'-'.$day."<br>\n"; if ($day == $jour && $month == $mois && $year == $annee) { // Scan all event for this date foreach ($eventarray[$daykey] as $index => $event) { $keysofuserassigned = array_keys($event->userassigned); if (!in_array($username->id, $keysofuserassigned)) { continue; } // We discard record if event is from another user than user we want to show //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show $parameters = array(); $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } $ponct = $event->date_start_in_calendar == $event->date_end_in_calendar; // Define $color (Hex string like '0088FF') and $cssclass of event $color = -1; $cssclass = ''; $colorindex = -1; if (in_array($user->id, $keysofuserassigned)) { $nummytasks++; $cssclass = 'family_mytasks'; if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { $color = $event->type_color; } } else { if ($event->type_code == 'ICALEVENT') { $numical++; if (!empty($event->icalname)) { if (!isset($numicals[dol_string_nospecial($event->icalname)])) { $numicals[dol_string_nospecial($event->icalname)] = 0; } $numicals[dol_string_nospecial($event->icalname)]++; } $color = $event->icalcolor; $cssclass = !empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other unsortable'; } else { if ($event->type_code == 'BIRTHDAY') { $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); } else { $numother++; $cssclass = 'family_other'; if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { $color = $event->type_color; } } } } if ($color < 0) { // Define color index if not yet defined $idusertouse = $event->userownerid ? $event->userownerid : 0; if (isset($colorindexused[$idusertouse])) { $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user } else { $colorindex = $nextindextouse; $colorindexused[$idusertouse] = $colorindex; if (!empty($theme_datacolor[$nextindextouse + 1])) { $nextindextouse++; } // Prepare to use next color } // Define color $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); } //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd; // Define all rects with event (cases1 is first half hour, cases2 is second half hour) for ($h = $begin_h; $h < $end_h; $h++) { //if ($username->id == 1 && $day==1) print 'h='.$h; $newcolor = ''; //init if (empty($event->fulldayevent)) { $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, false, false); $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, false, false); $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, false, false); $dateendtouse = $event->date_end_in_calendar; if ($dateendtouse == $event->date_start_in_calendar) { $dateendtouse++; } //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>'; if ($event->date_start_in_calendar < $b && $dateendtouse > $a) { $busy = $event->transparency; $cases1[$h][$event->id]['busy'] = $busy; $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour'); if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { $tmpa = dol_getdate($event->date_start_in_calendar, true); $tmpb = dol_getdate($event->date_end_in_calendar, true); if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { $cases1[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour'); } else { $cases1[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour'); } } $cases1[$h][$event->id]['string'] .= ' - ' . $event->label; $cases1[$h][$event->id]['typecode'] = $event->type_code; if ($event->socid) { //$cases1[$h][$event->id]['string'].='xxx'; } $cases1[$h][$event->id]['color'] = $color; } if ($event->date_start_in_calendar < $c && $dateendtouse > $b) { $busy = $event->transparency; $cases2[$h][$event->id]['busy'] = $busy; $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour'); if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { $tmpa = dol_getdate($event->date_start_in_calendar, true); $tmpb = dol_getdate($event->date_end_in_calendar, true); if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { $cases2[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour'); } else { $cases2[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour'); } } $cases2[$h][$event->id]['string'] .= ' - ' . $event->label; $cases2[$h][$event->id]['typecode'] = $event->type_code; if ($event->socid) { //$cases2[$h][$event->id]['string'].='xxx'; } $cases2[$h][$event->id]['color'] = $color; } } else { $busy = $event->transparency; $cases1[$h][$event->id]['busy'] = $busy; $cases2[$h][$event->id]['busy'] = $busy; $cases1[$h][$event->id]['string'] = $event->label; $cases2[$h][$event->id]['string'] = $event->label; $cases1[$h][$event->id]['typecode'] = $event->type_code; $cases2[$h][$event->id]['typecode'] = $event->type_code; $cases1[$h][$event->id]['color'] = $color; $cases2[$h][$event->id]['color'] = $color; } } $i++; } break; // We found the date we were looking for. No need to search anymore. } } for ($h = $begin_h; $h < $end_h; $h++) { $color1 = ''; $color2 = ''; $style1 = ''; $style2 = ''; $string1 = ' '; $string2 = ' '; $title1 = ''; $title2 = ''; if (isset($cases1[$h]) && $cases1[$h] != '') { //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events")); if (count($cases1[$h]) > 1) { $title1 .= count($cases1[$h]) . ' ' . (count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); } $string1 = ' '; if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) { $style1 = 'peruser_notbusy'; } else { $style1 = 'peruser_busy'; } foreach ($cases1[$h] as $id => $ev) { if ($ev['busy']) { $style1 = 'peruser_busy'; } } } if (isset($cases2[$h]) && $cases2[$h] != '') { //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events")); if (count($cases2[$h]) > 1) { $title2 .= count($cases2[$h]) . ' ' . (count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); } $string2 = ' '; if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) { $style2 = 'peruser_notbusy'; } else { $style2 = 'peruser_busy'; } foreach ($cases2[$h] as $id => $ev) { if ($ev['busy']) { $style2 = 'peruser_busy'; } } } if ($h == $begin_h) { echo '<td class="' . $style . '_peruserleft cal_peruser"' . ($var ? ' style="background: #F8F8F8"' : '') . '>'; } else { echo '<td class="' . $style . ' cal_peruser"' . ($var ? ' style="background: #F8F8F8"' : '') . '>'; } if (count($cases1[$h]) == 1) { $ids = array_keys($cases1[$h]); $output = array_slice($cases1[$h], 0, 1); if ($output[0]['string']) { $title1 .= ($title1 ? ' - ' : '') . $output[0]['string']; } if ($output[0]['color']) { $color1 = $output[0]['color']; } } else { if (count($cases1[$h]) > 1) { $color1 = '222222'; } } if (count($cases2[$h]) == 1) { $ids = array_keys($cases2[$h]); $output = array_slice($cases2[$h], 0, 1); if ($output[0]['string']) { $title2 .= ($title2 ? ' - ' : '') . $output[0]['string']; } if ($output[0]['color']) { $color2 = $output[0]['color']; } } else { if (count($cases2[$h]) > 1) { $color2 = '222222'; } } $ids1 = ''; $ids2 = ''; if (count($cases1[$h]) && array_keys($cases1[$h])) { $ids1 = join(',', array_keys($cases1[$h])); } if (count($cases2[$h]) && array_keys($cases2[$h])) { $ids2 = join(',', array_keys($cases2[$h])); } //var_dump($cases1[$h]); print '<table class="nobordernopadding" width="100%">'; print '<tr><td ' . ($color1 ? 'style="background: #' . $color1 . ';"' : '') . 'class="' . ($style1 ? $style1 . ' ' : '') . 'onclickopenref' . ($title1 ? ' cursorpointer' : '') . '" ref="ref_' . $username->id . '_' . sprintf("%04d", $year) . '_' . sprintf("%02d", $month) . '_' . sprintf("%02d", $day) . '_' . sprintf("%02d", $h) . '_00_' . ($ids1 ? $ids1 : 'none') . '"' . ($title1 ? ' title="' . $title1 . '"' : '') . '>'; print $string1; print '</td><td ' . ($color2 ? 'style="background: #' . $color2 . ';"' : '') . 'class="' . ($style2 ? $style2 . ' ' : '') . 'onclickopenref' . ($title1 ? ' cursorpointer' : '') . '" ref="ref_' . $username->id . '_' . sprintf("%04d", $year) . '_' . sprintf("%02d", $month) . '_' . sprintf("%02d", $day) . '_' . sprintf("%02d", $h) . '_30_' . ($ids2 ? $ids2 : 'none') . '"' . ($title2 ? ' title="' . $title2 . '"' : '') . '>'; print $string2; print '</td></tr>'; print '</table>'; print '</td>'; } }
/** * Build a graph onto disk using JFlot library. Input when calling this method should be: * $this->data = array(array( 0=>'labelxA', 1=>yA), array('labelxB',yB)); or * $this->data = array(array('label'=>'labelxA','data'=>yA), array('labelxB',yB)); // TODO Syntax not supported. Removed when dol_print_graph_removed * $this->data = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn)); // when there is n series to show for each x * $this->legend= array("Val1",...,"Valn"); // list of n series name * $this->type = array('bars',...'lines'); or array('pie') * $this->mode = 'depth' ??? * $this->bgcolorgrid * $this->datacolor * * @param string $file Image file name to use to save onto disk (also used as javascript unique id) * @param string $fileurl Url path to show image if saved onto disk * @return void */ private function draw_jflot($file, $fileurl) { global $artichow_defaultfont; dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type)); if (empty($this->width) && empty($this->height)) { print 'Error width or height not set'; return; } $legends = array(); $nblot = count($this->data[0]) - 1; // -1 to remove legend if ($nblot < 0) { dol_print_error('Bad value for property ->data. Must be set by mydolgraph->SetData before callinf mydolgrapgh->draw'); } $firstlot = 0; // Works with line but not with bars //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x $i = $firstlot; $serie = array(); while ($i < $nblot) { $values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x $serie[$i] = "var d" . $i . " = [];\n"; // Fill array $values $x = 0; foreach ($this->data as $valarray) { $legends[$x] = $valarray[0]; $values[$x] = is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] : null; $x++; } // TODO Avoid push by adding generated long array... if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') { foreach ($values as $x => $y) { if (isset($y)) { $serie[$i] .= 'd' . $i . '.push({"label":"' . dol_escape_js($legends[$x]) . '", "data":' . $y . '});' . "\n"; } } } else { foreach ($values as $x => $y) { if (isset($y)) { $serie[$i] .= 'd' . $i . '.push([' . $x . ', ' . $y . ']);' . "\n"; } } } unset($values); $i++; } $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $this->_stringtoshow = '<!-- Build using ' . $this->_library . ' -->' . "\n"; if (!empty($this->title)) { $this->_stringtoshow .= '<div align="center" class="dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>'; } $this->_stringtoshow .= '<div id="placeholder_' . $tag . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="dolgraph' . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . '"></div>' . "\n"; $this->_stringtoshow .= '<script id="' . $tag . '">' . "\n"; $this->_stringtoshow .= '$(function () {' . "\n"; $i = $firstlot; while ($i < $nblot) { $this->_stringtoshow .= $serie[$i]; $i++; } $this->_stringtoshow .= "\n"; // Special case for Graph of type 'pie' if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') { $datacolor = array(); foreach ($this->datacolor as $val) { $datacolor[] = "#" . sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); } $urltemp = ''; // TODO Add support for url link into labels $showlegend = $this->showlegend; $showpointvalue = $this->showpointvalue; $showpercent = $this->showpercent; $this->_stringtoshow .= ' function plotWithOptions_' . $tag . '() { $.plot($("#placeholder_' . $tag . '"), d0, { series: { pie: { show: true, radius: 3/4, label: { show: true, radius: 3/4, formatter: function(label, series) { var percent=Math.round(series.percent); var number=series.data[0][1]; return \''; $this->_stringtoshow .= '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'; if ($urltemp) { $this->_stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="' . $urltemp . '">'; } $this->_stringtoshow .= '\'+'; $this->_stringtoshow .= $showlegend ? '' : 'label+\'<br/>\'+'; // Hide label if already shown in legend $this->_stringtoshow .= $showpointvalue ? 'number+' : ''; $this->_stringtoshow .= $showpercent ? '\'<br/>\'+percent+\'%\'+' : ''; $this->_stringtoshow .= '\''; if ($urltemp) { $this->_stringtoshow .= '</a>'; } $this->_stringtoshow .= '</div>\'; }, background: { opacity: 0.5, color: \'#000000\' } } } }, zoom: { interactive: true }, pan: { interactive: true },'; if (count($datacolor)) { $this->_stringtoshow .= 'colors: ' . (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)) . ','; } $this->_stringtoshow .= 'legend: {show: ' . ($showlegend ? 'true' : 'false') . ', position: \'ne\' } }); }' . "\n"; } else { // Add code to support tooltips $this->_stringtoshow .= ' function showTooltip_' . $tag . '(x, y, contents) { $(\'<div id="tooltip_' . $tag . '">\' + contents + \'</div>\').css({ position: \'absolute\', display: \'none\', top: y + 5, left: x + 5, border: \'1px solid #ddd\', padding: \'2px\', \'background-color\': \'#ffe\', width: 200, opacity: 0.80 }).appendTo("body").fadeIn(20); } var previousPoint = null; $("#placeholder_' . $tag . '").bind("plothover", function (event, pos, item) { $("#x").text(pos.x.toFixed(2)); $("#y").text(pos.y.toFixed(2)); if (item) { if (previousPoint != item.dataIndex) { previousPoint = item.dataIndex; $("#tooltip").remove(); /* console.log(item); */ var x = item.datapoint[0].toFixed(2); var y = item.datapoint[1].toFixed(2); var z = item.series.xaxis.ticks[item.dataIndex].label; '; if ($this->showpointvalue > 0) { $this->_stringtoshow .= ' showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); '; } $this->_stringtoshow .= ' } } else { $("#tooltip_' . $tag . '").remove(); previousPoint = null; } }); '; $this->_stringtoshow .= 'var stack = null, steps = false;' . "\n"; $this->_stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n"; $this->_stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n"; $i = $firstlot; while ($i < $nblot) { if ($i > $firstlot) { $this->_stringtoshow .= ', ' . "\n"; } $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); $this->_stringtoshow .= '{ '; if (!isset($this->type[$i]) || $this->type[$i] == 'bars') { $this->_stringtoshow .= 'bars: { show: true, align: "' . ($i == $firstlot ? 'center' : 'left') . '", barWidth: 0.5 }, '; } if (isset($this->type[$i]) && $this->type[$i] == 'lines') { $this->_stringtoshow .= 'lines: { show: true, fill: false }, '; } $this->_stringtoshow .= 'color: "#' . $color . '", label: "' . (isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '') . '", data: d' . $i . ' }'; $i++; } $this->_stringtoshow .= "\n" . ' ], { series: { stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6 } }' . "\n"; // Xaxis $this->_stringtoshow .= ', xaxis: { ticks: [' . "\n"; $x = 0; foreach ($this->data as $key => $valarray) { if ($x > 0) { $this->_stringtoshow .= ', ' . "\n"; } $this->_stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]'; $x++; } $this->_stringtoshow .= '] }' . "\n"; // Yaxis $this->_stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . $this->MaxValue . ' }' . "\n"; // Background color $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]); $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); $this->_stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 . '", "#' . $color2 . '"] } }' . "\n"; //$this->_stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this $this->_stringtoshow .= '});' . "\n"; $this->_stringtoshow .= '}' . "\n"; } $this->_stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n"; $this->_stringtoshow .= '});' . "\n"; $this->_stringtoshow .= '</script>' . "\n"; }
/** * Build a login from lastname, firstname * * @param string $lastname Lastname * @param string $firstname Firstname * @return string Login */ function dol_buildlogin($lastname, $firstname) { $login = strtolower(dol_string_unaccent($firstname)); $login .= $login ? '.' : ''; $login .= strtolower(dol_string_unaccent($lastname)); $login = dol_string_nospecial($login, ''); // For special names return $login; }
/** * Show event of a particular day * * @param DoliDB $db Database handler * @param int $day Day * @param int $month Month * @param int $year Year * @param int $monthshown Current month shown in calendar view * @param string $style Style to use for this day * @param array $eventarray Array of events * @param int $maxprint Nb of actions to show each day on month view (0 means no limit) * @param int $maxnbofchar Nb of characters to show for event line * @param string $newparam Parameters on current URL * @param int $showinfo Add extended information (used by day and week view) * @param int $minheight Minimum height for each event. 60px by default. * @return void */ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60) { global $user, $conf, $langs; global $action, $filter, $filtert, $status, $actioncode; // Filters used into search form global $theme_datacolor; global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused; print "\n" . '<div id="dayevent_' . sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day) . '" class="dayevent">'; // Line with title of day $curtime = dol_mktime(0, 0, 0, $month, $day, $year); print '<table class="nobordernopadding" width="100%">' . "\n"; print '<tr><td align="left" class="nowrap">'; print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?'; print 'action=show_day&day=' . str_pad($day, 2, "0", STR_PAD_LEFT) . '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year; print $newparam; print '">'; if ($showinfo) { print dol_print_date($curtime, 'daytextshort'); } else { print dol_print_date($curtime, '%d'); } print '</a>'; print '</td><td align="right" class="nowrap">'; if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) { $newparam .= '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year; //$param='month='.$monthshown.'&year='.$year; $hourminsec = '100000'; print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&datep=' . sprintf("%04d%02d%02d", $year, $month, $day) . $hourminsec . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . ($newparam ? '?' . $newparam : '')) . '">'; print img_picto($langs->trans("NewAction"), 'edit_add.png'); print '</a>'; } print '</td></tr>' . "\n"; // Line with td contains all div of each events print '<tr height="' . $minheight . '"><td valign="top" colspan="2" class="sortable" style="padding-bottom: 2px;">'; print '<div style="width: 100%; position: relative;">'; //$curtime = dol_mktime (0, 0, 0, $month, $day, $year); $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array(); $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day); $nextindextouse = count($colorindexused); // At first run this is 0, so fist user has 0, next 1, ... //print $nextindextouse; foreach ($eventarray as $daykey => $notused) { $annee = date('Y', $daykey); $mois = date('m', $daykey); $jour = date('d', $daykey); if ($day == $jour && $month == $mois && $year == $annee) { foreach ($eventarray[$daykey] as $index => $event) { if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { $keysofuserassigned = array_keys($event->userassigned); $ponct = $event->date_start_in_calendar == $event->date_end_in_calendar; // Define $color (Hex string like '0088FF') and $cssclass of event $color = -1; $colorindex = -1; if (in_array($user->id, $keysofuserassigned)) { $nummytasks++; $cssclass = 'family_mytasks'; if (empty($cacheusers[$event->userownerid])) { $newuser = new User($db); $newuser->fetch($event->userownerid); $cacheusers[$event->userownerid] = $newuser; } //var_dump($cacheusers[$event->userownerid]->color); // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) if (!empty($cacheusers[$event->userownerid]->color)) { $color = $cacheusers[$event->userownerid]->color; } } else { if ($event->type_code == 'ICALEVENT') { $numical++; if (!empty($event->icalname)) { if (!isset($numicals[dol_string_nospecial($event->icalname)])) { $numicals[dol_string_nospecial($event->icalname)] = 0; } $numicals[dol_string_nospecial($event->icalname)]++; } $color = $event->icalcolor; $cssclass = !empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other'; } else { if ($event->type_code == 'BIRTHDAY') { $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unmovable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); } else { $numother++; $cssclass = 'family_other'; if (empty($cacheusers[$event->userownerid])) { $newuser = new User($db); $newuser->fetch($event->userownerid); $cacheusers[$event->userownerid] = $newuser; } //var_dump($cacheusers[$event->userownerid]->color); // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) if (!empty($cacheusers[$event->userownerid]->color)) { $color = $cacheusers[$event->userownerid]->color; } } } } if ($color == -1) { // Define color index if not yet defined $idusertouse = $event->userownerid ? $event->userownerid : 0; if (isset($colorindexused[$idusertouse])) { $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user } else { $colorindex = $nextindextouse; $colorindexused[$idusertouse] = $colorindex; if (!empty($theme_datacolor[$nextindextouse + 1])) { $nextindextouse++; } // Prepare to use next color } //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>'; // Define color $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); } $cssclass = $cssclass . ' ' . $cssclass . '_day_' . $ymd; // Defined style to disable drag and drop feature if ($event->type_code == 'AC_OTH_AUTO') { $cssclass .= " unmovable"; } else { if ($event->type_code == 'ICALEVENT') { $cssclass .= " unmovable"; } else { if ($event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) { $tmpyearend = date('Y', $event->date_end_in_calendar); $tmpmonthend = date('m', $event->date_end_in_calendar); $tmpdayend = date('d', $event->date_end_in_calendar); if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) { $cssclass .= " unmovable"; } } else { $cssclass .= " movable"; } } } $h = ''; $nowrapontd = 1; if ($action == 'show_day') { $h = 'height: 100%; '; $nowrapontd = 0; } if ($action == 'show_week') { $h = 'height: 100%; '; $nowrapontd = 0; } // Show rect of event print "\n"; print '<!-- start event ' . $i . ' --><div id="event_' . $ymd . '_' . $i . '" class="event ' . $cssclass . '"'; //print ' style="height: 100px;'; //print ' position: absolute; top: 40px; width: 50%;'; //print '"'; print '>'; print '<ul class="cal_event" style="' . $h . '">'; // always 1 li per ul, 1 ul per event print '<li class="cal_event" style="' . $h . '">'; print '<table class="cal_event' . (empty($event->transparency) ? '' : ' cal_event_busy') . '" style="' . $h; print 'background: #' . $color . '; background: -webkit-gradient(linear, left top, left bottom, from(#' . $color . '), to(#' . dol_color_minus($color, 1) . '));'; //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));'; //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;'; print ' -moz-border-radius:4px;" width="100%"><tr>'; print '<td class="' . ($nowrapontd ? 'nowrap ' : '') . 'cal_event' . ($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '') . '">'; if ($event->type_code == 'BIRTHDAY') { print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact'); } if ($event->type_code != 'BIRTHDAY') { // Picto if (empty($event->fulldayevent)) { //print $event->getNomUrl(2).' '; } // Date if (empty($event->fulldayevent)) { //print '<strong>'; $daterange = ''; // Show hours (start ... end) $tmpyearstart = date('Y', $event->date_start_in_calendar); $tmpmonthstart = date('m', $event->date_start_in_calendar); $tmpdaystart = date('d', $event->date_start_in_calendar); $tmpyearend = date('Y', $event->date_end_in_calendar); $tmpmonthend = date('m', $event->date_end_in_calendar); $tmpdayend = date('d', $event->date_end_in_calendar); // Hour start if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) { $daterange .= dol_print_date($event->date_start_in_calendar, '%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) { $daterange .= '-'; } //else //print '...'; } } if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) { $daterange .= '...'; } } // Hour end if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) { $daterange .= dol_print_date($event->date_end_in_calendar, '%H:%M'); } // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user } //print $daterange; if ($event->type_code != 'ICALEVENT') { $savlabel = $event->libelle; $event->libelle = $daterange; print $event->getNomUrl(0); $event->libelle = $savlabel; } else { print $daterange; } //print '</strong> '; print "<br>\n"; } else { if ($showinfo) { print $langs->trans("EventOnFullDay") . "<br>\n"; } } // Show title if ($event->type_code == 'ICALEVENT') { print dol_trunc($event->libelle, $maxnbofchar); } else { print $event->getNomUrl(0, $maxnbofchar, 'cal_event'); } if ($event->type_code == 'ICALEVENT') { print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')'; } // If action related to company / contact $linerelatedto = ''; $length = 16; if (!empty($event->societe->id) && !empty($event->contact->id)) { $length = round($length / 2); } if (!empty($event->societe->id) && $event->societe->id > 0) { if (!isset($cachethirdparties[$event->societe->id]) || !is_object($cachethirdparties[$event->societe->id])) { $thirdparty = new Societe($db); $thirdparty->fetch($event->societe->id); $cachethirdparties[$event->societe->id] = $thirdparty; } else { $thirdparty = $cachethirdparties[$event->societe->id]; } if (!empty($thirdparty->id)) { $linerelatedto .= $thirdparty->getNomUrl(1, '', $length); } } if (!empty($event->contact->id) && $event->contact->id > 0) { if (!is_object($cachecontacts[$event->contact->id])) { $contact = new Contact($db); $contact->fetch($event->contact->id); $cachecontacts[$event->contact->id] = $contact; } else { $contact = $cachecontacts[$event->contact->id]; } if ($linerelatedto) { $linerelatedto .= ' / '; } if (!empty($contact->id)) { $linerelatedto .= $contact->getNomUrl(1, '', $length); } } if ($linerelatedto) { print '<br>' . $linerelatedto; } } // Show location if ($showinfo) { if ($event->location) { print '<br>'; print $langs->trans("Location") . ': ' . $event->location; } } print '</td>'; // Status - Percent print '<td align="right" class="nowrap cal_event_right">'; if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') { print $event->getLibStatut(3, 1); } else { print ' '; } print '</td></tr></table>'; print '</li>'; print '</ul>'; print '</div><!-- end event ' . $i . ' -->' . "\n"; $i++; } else { print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?action=' . $action . '&maxprint=0&month=' . $monthshown . '&year=' . $year; print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . $filter : ''); print $filtert ? '&filtert=' . $filtert : ''; print $actioncode != '' ? '&actioncode=' . $actioncode : ''; print '">' . img_picto("all", "1downarrow_selected.png") . ' ...'; print ' +' . (count($eventarray[$daykey]) - $maxprint); print '</a>'; break; //$ok=false; // To avoid to show twice the link } } break; } } if (!$i) { print ' '; } if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint) { print '<div id="more_' . $ymd . '">' . img_picto("all", "1downarrow_selected.png") . ' +' . $langs->trans("More") . '...</div>'; //print ' +'.(count($eventarray[$daykey])-$maxprint); print '<script type="text/javascript">' . "\n"; print 'jQuery(document).ready(function () {' . "\n"; print 'jQuery("#more_' . $ymd . '").click(function() { reinit_day_' . $ymd . '(); });' . "\n"; print 'function reinit_day_' . $ymd . '() {' . "\n"; print 'var nb=0;' . "\n"; // TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached print 'jQuery(".family_mytasks_day_' . $ymd . '").toggle();'; print '}' . "\n"; print '});' . "\n"; print '</script>' . "\n"; } print '</div>'; print '</td></tr>'; print '</table></div>' . "\n"; }
/** * Update a record into database * * @param int $id Id of product * @param User $user Object user making update * @param int $notrigger Disable triggers * @param string $action Current action for hookmanager ('add' or 'update') * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user, $notrigger = false, $action = 'update') { global $langs, $conf, $hookmanager; $error = 0; // Check parameters if (!$this->label) { $this->label = 'MISSING LABEL'; } // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->label = trim($this->label); $this->description = trim($this->description); $this->note = isset($this->note) ? trim($this->note) : null; $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->tva_npr)) { $this->tva_npr = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->status)) { $this->status = 0; } if (empty($this->status_buy)) { $this->status_buy = 0; } if (empty($this->country_id)) { $this->country_id = 0; } // Barcode value $this->barcode = trim($this->barcode); $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell = trim($this->accountancy_code_sell); $this->db->begin(); // Check name is required and codes are ok or unique. // If error, this->errors[] is filled if ($action != 'add') { $result = $this->verify(); // We don't check when update called during a create because verify was already done } if ($result >= 0) { if (empty($this->oldcopy)) { $org = new self($this->db); $org->fetch($this->id); $this->oldcopy = $org; } // test if batch management is activated on existing product if ($this->hasbatch() && !$this->oldcopy->hasbatch()) { $this->load_stock(); foreach ($this->stock_warehouse as $idW => $ObjW) { $qty_batch = 0; foreach ($ObjW->detail_batch as $detail) { $qty_batch += $detail->qty; } // Quantities in batch details are not same same as stock quantity // So we add a default batch record if ($ObjW->real != $qty_batch) { $ObjBatch = new Productbatch($this->db); $ObjBatch->batch = $langs->trans('BatchDefaultNumber'); $ObjBatch->qty = $ObjW->real - $qty_batch; $ObjBatch->fk_product_stock = $ObjW->id; if ($ObjBatch->create($user, 1) < 0) { $error++; $this->errors = $ObjBatch->errors; } } } } // For automatic creation if ($this->barcode == -1) { $this->barcode = $this->get_barcode($this, $this->barcode_type_code); } $sql = "UPDATE " . MAIN_DB_PREFIX . "product"; $sql .= " SET label = '" . $this->db->escape($this->label) . "'"; $sql .= ", ref = '" . $this->db->escape($this->ref) . "'"; $sql .= ", ref_ext = " . (!empty($this->ref_ext) ? "'" . $this->db->escape($this->ref_ext) . "'" : "null"); $sql .= ", tva_tx = " . $this->tva_tx; $sql .= ", recuperableonly = " . $this->tva_npr; $sql .= ", localtax1_tx = " . $this->localtax1_tx; $sql .= ", localtax2_tx = " . $this->localtax2_tx; $sql .= ", barcode = " . (empty($this->barcode) ? "null" : "'" . $this->db->escape($this->barcode) . "'"); $sql .= ", fk_barcode_type = " . (empty($this->barcode_type) ? "null" : $this->db->escape($this->barcode_type)); $sql .= ", tosell = " . $this->status; $sql .= ", tobuy = " . $this->status_buy; $sql .= ", tobatch = " . (empty($this->status_batch) || $this->status_batch < 0 ? '0' : $this->status_batch); $sql .= ", finished = " . (!isset($this->finished) || $this->finished < 0 ? "null" : (int) $this->finished); $sql .= ", weight = " . ($this->weight != '' ? "'" . $this->weight . "'" : 'null'); $sql .= ", weight_units = " . ($this->weight_units != '' ? "'" . $this->weight_units . "'" : 'null'); $sql .= ", length = " . ($this->length != '' ? "'" . $this->length . "'" : 'null'); $sql .= ", length_units = " . ($this->length_units != '' ? "'" . $this->length_units . "'" : 'null'); $sql .= ", surface = " . ($this->surface != '' ? "'" . $this->surface . "'" : 'null'); $sql .= ", surface_units = " . ($this->surface_units != '' ? "'" . $this->surface_units . "'" : 'null'); $sql .= ", volume = " . ($this->volume != '' ? "'" . $this->volume . "'" : 'null'); $sql .= ", volume_units = " . ($this->volume_units != '' ? "'" . $this->volume_units . "'" : 'null'); $sql .= ", seuil_stock_alerte = " . (isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '' ? "'" . $this->seuil_stock_alerte . "'" : "null"); $sql .= ", description = '" . $this->db->escape($this->description) . "'"; $sql .= ", url = " . ($this->url ? "'" . $this->db->escape($this->url) . "'" : 'null'); $sql .= ", customcode = '" . $this->db->escape($this->customcode) . "'"; $sql .= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql .= ", note = " . (isset($this->note) ? "'" . $this->db->escape($this->note) . "'" : 'null'); $sql .= ", duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) . "'"; $sql .= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) . "'"; $sql .= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ", desiredstock = " . (isset($this->desiredstock) && $this->desiredstock != '' ? $this->desiredstock : "null"); $sql .= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= " WHERE rowid = " . $id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if (!empty($conf->global->MAIN_MULTILANGS)) { if ($this->setMultiLangs() < 0) { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; return -2; } } $action = 'update'; // Actions on extra fields (by external module or standard code) $hookmanager->initHooks(array('productdao')); $parameters = array('id' => $this->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } else { if ($reshook < 0) { $error++; } } if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('PRODUCT_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->product->dir_output) { $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $res = dol_move($olddir, $newdir); if (!$res) { $this->error = 'ErrorFailToMoveDir'; $error++; } } } } if (!$error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { if (empty($conf->barcode->enabled)) { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductAlreadyExists", $this->ref); } else { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductBarCodeAlreadyExists", $this->barcode); } $this->db->rollback(); return -1; } else { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; $this->db->rollback(); return -2; } } } else { $this->db->rollback(); dol_syslog(get_class($this) . "::Update fails verify " . join(',', $this->errors), LOG_WARNING); return -3; } }
/** * Show event of a particular day * * @param DoliDB $db Database handler * @param int $day Day * @param int $month Month * @param int $year Year * @param int $monthshown Current month shown in calendar view * @param string $style Style to use for this day * @param array &$eventarray Array of events * @param int $maxprint Nb of actions to show each day on month view (0 means no limit) * @param int $maxnbofchar Nb of characters to show for event line * @param string $newparam Parameters on current URL * @param int $showinfo Add extended information (used by day view) * @param int $minheight Minimum height for each event. 60px by default. * @return void */ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60) { global $user, $conf, $langs; global $filter, $filtera, $filtert, $filterd, $status; global $theme_datacolor; global $cachethirdparties, $cachecontacts; print '<div id="dayevent_' . sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day) . '" class="dayevent">' . "\n"; $curtime = dol_mktime(0, 0, 0, $month, $day, $year); print '<table class="nobordernopadding" width="100%">'; print '<tr style="background: #EEEEEE"><td align="left" nowrap="nowrap">'; print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?'; print 'action=show_day&day=' . str_pad($day, 2, "0", STR_PAD_LEFT) . '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year; print $newparam; //.'&month='.$month.'&year='.$year; print '">'; if ($showinfo) { print dol_print_date($curtime, 'daytext'); } else { print dol_print_date($curtime, '%d'); } print '</a>'; print '</td><td align="right" nowrap="nowrap">'; if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) { //$param='month='.$monthshown.'&year='.$year; $hourminsec = '100000'; print '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create&datep=' . sprintf("%04d%02d%02d", $year, $month, $day) . $hourminsec . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . ($newparam ? '?' . $newparam : '')) . '">'; print img_picto($langs->trans("NewAction"), 'edit_add.png'); print '</a>'; } print '</td></tr>'; print '<tr height="' . $minheight . '"><td valign="top" colspan="2" nowrap="nowrap">'; //$curtime = dol_mktime (0, 0, 0, $month, $day, $year); $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array(); $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day); foreach ($eventarray as $daykey => $notused) { $annee = date('Y', $daykey); $mois = date('m', $daykey); $jour = date('d', $daykey); if ($day == $jour && $month == $mois && $year == $annee) { foreach ($eventarray[$daykey] as $index => $event) { if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { $ponct = $event->date_start_in_calendar == $event->date_end_in_calendar; // Define $color and $cssclass of event $color = -1; $cssclass = ''; $colorindex = -1; if ($event->author->id == $user->id || $event->usertodo->id == $user->id || $event->userdone->id == $user->id) { $nummytasks++; $colorindex = 1; $cssclass = 'family_mytasks'; } else { if ($event->type_code == 'ICALEVENT') { $numical++; $numicals[dol_string_nospecial($event->icalname)]++; $color = $event->icalcolor; $cssclass = $event->icalname ? 'family_' . dol_string_nospecial($event->icalname) : 'family_other'; } else { if ($event->type_code == 'BIRTHDAY') { $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday'; } else { $numother++; $colorindex = 2; $cssclass = 'family_other'; } } } if ($color == -1) { $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); } $cssclass = $cssclass . ' ' . $cssclass . '_day_' . $ymd; // Show rect of event print '<div id="event_' . $ymd . '_' . $i . '" class="event ' . $cssclass . '">'; print '<table class="cal_event" style="background: #' . $color . '; -moz-border-radius:4px;" width="100%"><tr>'; print '<td nowrap="nowrap">'; if ($event->type_code == 'BIRTHDAY') { print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact'); } if ($event->type_code != 'BIRTHDAY') { // Picto if (empty($event->fulldayevent)) { //print $event->getNomUrl(2).' '; } // Date if (empty($event->fulldayevent)) { //print '<strong>'; $daterange = ''; // Show hours (start ... end) $tmpyearstart = date('Y', $event->date_start_in_calendar); $tmpmonthstart = date('m', $event->date_start_in_calendar); $tmpdaystart = date('d', $event->date_start_in_calendar); $tmpyearend = date('Y', $event->date_end_in_calendar); $tmpmonthend = date('m', $event->date_end_in_calendar); $tmpdayend = date('d', $event->date_end_in_calendar); // Hour start if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) { $daterange .= dol_print_date($event->date_start_in_calendar, '%H:%M'); if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) { $daterange .= '-'; } //else //print '...'; } } if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) { $daterange .= '...'; } } // Hour end if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) { if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) { $daterange .= dol_print_date($event->date_end_in_calendar, '%H:%M'); } } //print $daterange; if ($event->type_code != 'ICALEVENT') { $savlabel = $event->libelle; $event->libelle = $daterange; print $event->getNomUrl(0); $event->libelle = $savlabel; } else { print $daterange; } //print '</strong> '; print "<br>\n"; } else { if ($showinfo) { print $langs->trans("EventOnFullDay") . "<br>\n"; } } // Show title if ($event->type_code == 'ICALEVENT') { print dol_trunc($event->libelle, $maxnbofchar); } else { print $event->getNomUrl(0, $maxnbofchar, 'cal_event'); } if ($event->type_code == 'ICALEVENT') { print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')'; } // If action related to company / contact $linerelatedto = ''; $length = 16; if (!empty($event->societe->id) && !empty($event->contact->id)) { $length = round($length / 2); } if (!empty($event->societe->id) && $event->societe->id > 0) { if (!isset($cachethirdparties[$event->societe->id]) || !is_object($cachethirdparties[$event->societe->id])) { $thirdparty = new Societe($db); $thirdparty->fetch($event->societe->id); $cachethirdparties[$event->societe->id] = $thirdparty; } else { $thirdparty = $cachethirdparties[$event->societe->id]; } $linerelatedto .= $thirdparty->getNomUrl(1, '', $length); } if (!empty($event->contact->id) && $event->contact->id > 0) { if (!is_object($cachecontacts[$event->contact->id])) { $contact = new Contact($db); $contact->fetch($event->contact->id); $cachecontacts[$event->contact->id] = $contact; } else { $contact = $cachecontacts[$event->contact->id]; } if ($linerelatedto) { $linerelatedto .= ' / '; } $linerelatedto .= $contact->getNomUrl(1, '', $length); } if ($linerelatedto) { print '<br>' . $linerelatedto; } } // Show location if ($showinfo) { if ($event->location) { print '<br>'; print $langs->trans("Location") . ': ' . $event->location; } } print '</td>'; // Status - Percent print '<td align="right" nowrap="nowrap">'; if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') { print $event->getLibStatut(3, 1); } else { print ' '; } print '</td></tr></table>'; print '</div>'; $i++; } else { print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?maxprint=0&month=' . $monthshown . '&year=' . $year; print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . $filter : ''); print ($filtera ? '&filtera=' . $filtera : '') . ($filtert ? '&filtert=' . $filtert : '') . ($filterd ? '&filterd=' . $filterd : ''); print '">' . img_picto("all", "1downarrow_selected.png") . ' ...'; print ' +' . (count($eventarray[$daykey]) - $maxprint); print '</a>'; break; //$ok=false; // To avoid to show twice the link } } break; } } if (!$i) { print ' '; } if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint) { print '<div id="more_' . $ymd . '">' . img_picto("all", "1downarrow_selected.png") . ' +' . $langs->trans("More") . '...</div>'; //print ' +'.(count($eventarray[$daykey])-$maxprint); print '<script type="text/javascript">' . "\n"; print 'jQuery(document).ready(function () {' . "\n"; print 'jQuery("#more_' . $ymd . '").click(function() { reinit_day_' . $ymd . '(); });' . "\n"; print 'function reinit_day_' . $ymd . '() {' . "\n"; print 'var nb=0;' . "\n"; // TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached print 'jQuery(".family_mytasks_day_' . $ymd . '").toggle();'; print '}' . "\n"; print '});' . "\n"; print '</script>' . "\n"; } print '</td></tr>'; print '</table>'; print '</div>' . "\n"; }
if ($id > 0) { $_GET["id"] = $id; // Force chargement page en mode visu } else { setEventMessages($account->error, $account->errors, 'errors'); $action = 'create'; // Force chargement page en mode creation } } } if ($_POST["action"] == 'update' && !$_POST["cancel"]) { $error = 0; // Update account $account = new Account($db); $account->fetch($_POST["id"]); $account->ref = dol_string_nospecial(trim($_POST["ref"])); $account->label = trim($_POST["label"]); $account->courant = $_POST["type"]; $account->clos = $_POST["clos"]; $account->rappro = isset($_POST["norappro"]) && $_POST["norappro"] ? 0 : 1; $account->url = trim($_POST["url"]); $account->bank = trim($_POST["bank"]); $account->code_banque = trim($_POST["code_banque"]); $account->code_guichet = trim($_POST["code_guichet"]); $account->number = trim($_POST["number"]); $account->cle_rib = trim($_POST["cle_rib"]); $account->bic = trim($_POST["bic"]); $account->iban = trim($_POST["iban"]); $account->domiciliation = trim($_POST["domiciliation"]); $account->proprio = trim($_POST["proprio"]); $account->owner_address = trim($_POST["owner_address"]);
/** * Update a record into database * * @param int $id Id of product * @param User $user Object user making update * @param int $notrigger Disable triggers * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user, $notrigger=false) { global $langs, $conf; $error=0; $this->db->begin(); // Verification parametres if (! $this->libelle) $this->libelle = 'MISSING LABEL'; // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->libelle = trim($this->libelle); $this->description = trim($this->description); $this->note = trim($this->note); $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) $this->tva_tx = 0; if (empty($this->tva_npr)) $this->tva_npr = 0; //Local taxes if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; if (empty($this->finished)) $this->finished = 0; if (empty($this->country_id)) $this->country_id = 0; $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); $sql = "UPDATE ".MAIN_DB_PREFIX."product"; $sql.= " SET label = '" . $this->db->escape($this->libelle) ."'"; $sql.= ",ref = '" . $this->ref ."'"; $sql.= ",tva_tx = " . $this->tva_tx; $sql.= ",recuperableonly = " . $this->tva_npr; //Local taxes $sql.= ",localtax1_tx = " . $this->localtax1_tx; $sql.= ",localtax2_tx = " . $this->localtax2_tx; $sql.= ",tosell = " . $this->status; $sql.= ",tobuy = " . $this->status_buy; $sql.= ",finished = " . ($this->finished<0 ? "null" : $this->finished); $sql.= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); $sql.= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); $sql.= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); $sql.= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null'); $sql.= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null'); $sql.= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null'); $sql.= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); $sql.= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null'); $sql.= ",seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null"); $sql.= ",description = '" . $this->db->escape($this->description) ."'"; $sql.= ",customcode = '" . $this->db->escape($this->customcode) ."'"; $sql.= ",fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql.= ",note = '" . $this->db->escape($this->note) ."'"; $sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; $sql.= " WHERE rowid = " . $id; dol_syslog(get_class($this)."update sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if($conf->global->MAIN_MULTILANGS) { if ( $this->setMultiLangs() < 0) { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } // Actions on extra fields (by external module or standard code) include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('productdao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { $result=$this->insertExtraFields(); if ($result < 0) { $error++; } } else if ($reshook < 0) $error++; if (! $error && ! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->product->dir_output) { $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { $res=@dol_move($olddir, $newdir); if (! $res) { $this->error='ErrorFailToMoveDir'; $error++; } } } } if (! $error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); return -1; } else { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } }
/** * Build a graph onto disk using JFlot library * $graph_data = array(array('labelxA',yA),array('labelxB',yB)); * $graph_data = array(array('labelxA',yA1,...,yAn),array('labelxB',yB1,...yBn)); // when there is n value to show for each x * $legend = array("Val1",...,"Valn"); // list of n series name * * @param string $file Image file name to use if we save onto disk * @param string $fileurl Url path to show image if saved onto disk * @return void */ private function draw_jflot($file, $fileurl) { global $artichow_defaultfont; dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type)); // On boucle sur chaque lot de donnees $legends = array(); $nblot = count($this->data[0]) - 1; // -1 to remove legend $firstlot = 0; if ($nblot > 2) { $firstlot = $nblot - 2; } // We limit nblot to 2 because jflot can't manage more than 2 bars on same x $i = $firstlot; $serie = array(); while ($i < $nblot) { $x = 0; $values = array(); foreach ($this->data as $key => $valarray) { $legends[$x] = $valarray[0]; $values[$x] = $valarray[$i + 1]; $x++; } // We fix unknown values to null $newvalues = array(); foreach ($values as $val) { $newvalues[] = is_numeric($val) ? $val : null; } //print "Lot de donnees $i<br>"; //print_r($values); //print '<br>'; $serie[$i] = "var d" . $i . " = [];\n"; $x = 0; foreach ($newvalues as $key => $val) { if (isset($val)) { $serie[$i] .= "d" . $i . ".push([" . $x . ", " . $val . "]);\n"; } $x++; } $i++; } $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $this->_stringtoshow = '<!-- Build using ' . $this->_library . ' -->' . "\n"; $this->_stringtoshow .= '<br><div align="center">' . $this->title . '</div><br>'; $this->_stringtoshow .= '<div id="placeholder_' . $tag . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;"></div>' . "\n"; $this->_stringtoshow .= '<script id="' . $tag . '">' . "\n"; $this->_stringtoshow .= '$(function () {' . "\n"; $i = $firstlot; while ($i < $nblot) { $this->_stringtoshow .= $serie[$i]; $i++; } $this->_stringtoshow .= "\n"; $this->_stringtoshow .= ' function showTooltip_' . $tag . '(x, y, contents) { $(\'<div id="tooltip_' . $tag . '">\' + contents + \'</div>\').css( { position: \'absolute\', display: \'none\', top: y + 5, left: x + 5, border: \'1px solid #ddd\', padding: \'2px\', \'background-color\': \'#ffe\', width: 200, opacity: 0.80 }).appendTo("body").fadeIn(20); } var previousPoint = null; $("#placeholder_' . $tag . '").bind("plothover", function (event, pos, item) { $("#x").text(pos.x.toFixed(2)); $("#y").text(pos.y.toFixed(2)); if (item) { if (previousPoint != item.dataIndex) { previousPoint = item.dataIndex; $("#tooltip").remove(); /* console.log(item); */ var x = item.datapoint[0].toFixed(2); var y = item.datapoint[1].toFixed(2); var z = item.series.xaxis.ticks[item.dataIndex].label; showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); } } else { $("#tooltip_' . $tag . '").remove(); previousPoint = null; } }); '; $this->_stringtoshow .= 'var stack = null, steps = false;' . "\n"; $this->_stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n"; $this->_stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n"; $i = $firstlot; while ($i < $nblot) { if ($i > $firstlot) { $this->_stringtoshow .= ', ' . "\n"; } $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); $this->_stringtoshow .= '{ '; if (!isset($this->type[$i]) || $this->type[$i] == 'bars') { $this->_stringtoshow .= 'bars: { show: true, align: "' . ($i == $firstlot ? 'center' : 'left') . '", barWidth: 0.5 }, '; } if (isset($this->type[$i]) && $this->type[$i] == 'lines') { $this->_stringtoshow .= 'lines: { show: true, fill: false }, '; } $this->_stringtoshow .= 'color: "#' . $color . '", label: "' . (isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '') . '", data: d' . $i . ' }'; $i++; } $this->_stringtoshow .= "\n" . ' ], { series: { stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6 } }' . "\n"; // Xaxis $this->_stringtoshow .= ', xaxis: { ticks: [' . "\n"; $x = 0; foreach ($this->data as $key => $valarray) { if ($x > 0) { $this->_stringtoshow .= ', ' . "\n"; } $this->_stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]'; $x++; } $this->_stringtoshow .= '] }' . "\n"; // Yaxis $this->_stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . $this->MaxValue . ' }' . "\n"; // Background color $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]); $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); $this->_stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 . '", "#' . $color2 . '"] } }' . "\n"; //$this->_stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this $this->_stringtoshow .= '});' . "\n"; $this->_stringtoshow .= '}' . "\n"; $this->_stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n"; $this->_stringtoshow .= '});' . "\n"; $this->_stringtoshow .= '</script>' . "\n"; }
/** * Clean a string to use it as a file name. * @param str String to clean * @param newstr String to replace bad chars with * @return string String cleaned (a-zA-Z_) * @see dol_string_nospecial, dol_string_unaccent */ function dol_sanitizeFileName($str, $newstr = '_') { global $conf; return dol_string_nospecial(dol_string_unaccent($str), $newstr, $conf->filesystem_forbidden_chars); }
/** * Update a record into database * @param id Id of product * @param user Object user making update * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user) { global $langs, $conf; // Verification parametres if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT'; // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->libelle = trim($this->libelle); $this->description = trim($this->description); $this->note = trim($this->note); $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) $this->tva_tx = 0; if (empty($this->tva_npr)) $this->tva_npr = 0; //Local taxes if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; if (empty($this->finished)) $this->finished = 0; if (empty($this->hidden)) $this->hidden = 0; if (empty($this->country_id)) $this->country_id = 0; $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); $sql = "UPDATE ".MAIN_DB_PREFIX."product"; $sql.= " SET label = '" . $this->db->escape($this->libelle) ."'"; $sql.= ",ref = '" . $this->ref ."'"; $sql.= ",tva_tx = " . $this->tva_tx; $sql.= ",recuperableonly = " . $this->tva_npr; //Local taxes $sql.= ",localtax1_tx = " . $this->localtax1_tx; $sql.= ",localtax2_tx = " . $this->localtax2_tx; $sql.= ",tosell = " . $this->status; $sql.= ",tobuy = " . $this->status_buy; $sql.= ",finished = " . ($this->finished<0 ? "null" : $this->finished); $sql.= ",hidden = " . ($this->hidden<0 ? "null" : $this->hidden); $sql.= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); $sql.= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); $sql.= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); $sql.= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null'); $sql.= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null'); $sql.= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null'); $sql.= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); $sql.= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null'); $sql.= ",seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null"); $sql.= ",description = '" . $this->db->escape($this->description) ."'"; $sql.= ",customcode = '" . $this->db->escape($this->customcode) ."'"; $sql.= ",fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql.= ",note = '" . $this->db->escape($this->note) ."'"; $sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; $sql.= " WHERE rowid = " . $id; dol_syslog("Product::update sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if($conf->global->MAIN_MULTILANGS) { if ( $this->setMultiLangs() < 0) { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers return 1; } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); return -1; } else { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } }
function lineMapper_IMMECA($line) { if (empty($line[2])) { return false; } // Si label vide $Tab = array('label' => $line[2], 'qty' => $line[3], 'type' => 'line', 'product_ref' => dol_string_nospecial($line[1]), 'level' => 0, 'price' => $line[4]); return $Tab; }
/** * Show filter form in agenda view * * @param Object $form Form object * @param int $canedit Can edit filter fields * @param int $status Status * @param int $year Year * @param int $month Month * @param int $day Day * @param int $showbirthday Show birthday * @param string $filtera Filter on create by user * @param string $filtert Filter on assigned to user * @param string $filterd Filter of done by user * @param int $pid Product id * @param int $socid Third party id * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend * @param string $actioncode Preselected value of actioncode for filter on type * @return void */ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $showextcals = array(), $actioncode = '') { global $conf, $user, $langs, $db; // Filters print '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="status" value="' . $status . '">'; print '<input type="hidden" name="year" value="' . $year . '">'; print '<input type="hidden" name="month" value="' . $month . '">'; print '<input type="hidden" name="day" value="' . $day . '">'; print '<input type="hidden" name="showbirthday" value="' . $showbirthday . '">'; print '<table class="nobordernopadding" width="100%">'; print '<tr><td class="nowrap">'; print '<table class="nobordernopadding">'; if ($canedit) { print '<tr>'; print '<td class="nowrap">'; print $langs->trans("ActionsAskedBy"); print ' </td><td class="nowrap maxwidthonsmartphone">'; print $form->select_dolusers($filtera, 'userasked', 1, '', !$canedit); print '</td>'; print '</tr>'; print '<tr>'; print '<td class="nowrap">'; print $langs->trans("or") . ' ' . $langs->trans("ActionsToDoBy"); print ' </td><td class="nowrap maxwidthonsmartphone">'; print $form->select_dolusers($filtert, 'usertodo', 1, '', !$canedit); print '</td></tr>'; /*print '<tr>'; print '<td class="nowrap">'; print $langs->trans("or") . ' ' . $langs->trans("ActionsDoneBy"); print ' </td><td class="nowrap maxwidthonsmartphone">'; print $form->select_dolusers($filterd, 'userdone', 1, '', ! $canedit); print '</td></tr>';*/ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); print '<tr>'; print '<td class="nowrap">'; print $langs->trans("Type"); print ' </td><td class="nowrap maxwidthonsmartphone">'; print $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0); print '</td></tr>'; } if (!empty($conf->projet->enabled) && $user->rights->projet->lire) { require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; $formproject = new FormProjets($db); print '<tr>'; print '<td class="nowrap">'; print $langs->trans("Project") . ' '; print '</td><td class="nowrap maxwidthonsmartphone">'; $formproject->select_projects($socid ? $socid : -1, $pid, 'projectid', 64); print '</td></tr>'; } print '</table>'; print '</td>'; // Buttons print '<td align="center" valign="middle" class="nowrap">'; print img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewcal" value="' . $langs->trans("ViewCal") . '">'; print '<br>'; print img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewweek" value="' . $langs->trans("ViewWeek") . '">'; print '<br>'; print img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewday" value="' . $langs->trans("ViewDay") . '">'; print '<br>'; print img_picto($langs->trans("ViewList"), 'object_list', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewlist" value="' . $langs->trans("ViewList") . '">'; print '</td>'; // Legend if ($conf->use_javascript_ajax && is_array($showextcals)) { print '<td align="center" valign="middle" class="nowrap">'; print '<script type="text/javascript">' . "\n"; print 'jQuery(document).ready(function () {' . "\n"; print 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });' . "\n"; print 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n"; print 'jQuery(".family_birthday").toggle();' . "\n"; print '});' . "\n"; print '</script>' . "\n"; print '<table>'; if (!empty($conf->use_javascript_ajax)) { if (count($showextcals) > 0) { print '<tr><td><input type="checkbox" id="check_mytasks" name="check_mytasks" checked="true" disabled="disabled"> ' . $langs->trans("LocalAgenda") . '</td></tr>'; foreach ($showextcals as $val) { $htmlname = dol_string_nospecial($val['name']); print '<tr><td>'; print '<script type="text/javascript">' . "\n"; print 'jQuery(document).ready(function () {' . "\n"; print ' jQuery("#check_' . $htmlname . '").click(function() {'; print ' /* alert("' . $htmlname . '"); */'; print ' jQuery(".family_' . $htmlname . '").toggle();'; print ' });' . "\n"; print '});' . "\n"; print '</script>' . "\n"; print '<input type="checkbox" id="check_' . $htmlname . '" name="check_' . $htmlname . '" checked="true"> ' . $val['name']; print '</td></tr>'; } } } print '<tr><td>' . $langs->trans("AgendaShowBirthdayEvents") . ' <input type="checkbox" id="check_birthday" name="check_birthday"></td></tr>'; print '</table>'; print '</td>'; } print '</tr>'; print '</table>'; print '</form>'; }
/** * Clean a string to use it as a file name * * @param string $str String to clean * @param string $newstr String to replace bad chars with * @param int $unaccent 1=Remove also accent (default), 0 do not remove them * @return string String cleaned (a-zA-Z_) * * @see dol_string_nospecial, dol_string_unaccent */ function dol_sanitizeFileName($str, $newstr = '_', $unaccent = 1) { $filesystem_forbidden_chars = array('<', '>', ':', '/', '\\', '?', '*', '|', '"'); return dol_string_nospecial($unaccent ? dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars); }
/** * Function to build a document on disk using the generic odt module. * * @param Societe $object Object source to build document * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file * @param int $hidedetails Do not show line details * @param int $hidedesc Do not show desc * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) { global $user, $langs, $conf, $mysoc, $hookmanager; if (empty($srctemplatepath)) { dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); return -1; } // Add odtgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('odtgeneration')); global $action; if (!is_object($outputlangs)) { $outputlangs = $langs; } $sav_charset_output = $outputlangs->charset_output; $outputlangs->charset_output = 'UTF-8'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->societe->multidir_output[$object->entity]) { $dir = $conf->societe->multidir_output[$object->entity]; $objectref = dol_sanitizeFileName($object->id); if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } } if (file_exists($dir)) { //print "srctemplatepath=".$srctemplatepath; // Src filename $newfile = basename($srctemplatepath); $newfiletmp = preg_replace('/\\.od(s|t)/i', '', $newfile); $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); // Get extension (ods or odt) $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); if (!empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) { $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)) . '-' . $newfiletmp; } if (!empty($conf->global->MAIN_DOC_USE_TIMING)) { $format = $conf->global->MAIN_DOC_USE_TIMING; if ($format == '1') { $format = '%Y%m%d%H%M%S'; } $filename = $newfiletmp . '-' . dol_print_date(dol_now(), $format) . '.' . $newfileformat; } else { $filename = $newfiletmp . '.' . $newfileformat; } $file = $dir . '/' . $filename; $object->builddoc_filename = $filename; // For triggers //print "newfileformat=".$newfileformat; //print "newdir=".$dir; //print "newfile=".$newfile; //print "file=".$file; //print "conf->societe->dir_temp=".$conf->societe->dir_temp; //exit; dol_mkdir($conf->societe->multidir_temp[$object->entity]); // Open and load template require_once ODTPHP_PATH . 'odf.php'; try { $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}')); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } //print $odfHandler->__toString()."\n"; // Make substitutions into odt of user info $tmparray = $this->get_substitutionarray_user($user, $outputlangs); //var_dump($tmparray); exit; foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { //var_dump($value);exit; if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { //print $key.' '.$value;exit; $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { // setVars failed, probably because key not found } } // Make substitutions into odt of mysoc info $tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); //var_dump($tmparray); exit; foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { //var_dump($value);exit; if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { // setVars failed, probably because key not found } } // Replace tags of lines for contacts $contact_arrray = array(); $sql = "SELECT p.rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as p"; $sql .= " WHERE p.fk_soc = " . $object->id; $result = $this->db->query($sql); $num = $this->db->num_rows($result); $var = true; if ($num) { $i = 0; $contactstatic = new Contact($this->db); while ($i < $num) { $obj = $this->db->fetch_object($result); $contact_arrray[$i] = $obj->rowid; $i++; } } if (is_array($contact_arrray) && count($contact_arrray) > 0) { try { $listlines = $odfHandler->setSegment('companycontacts'); foreach ($contact_arrray as $array_key => $contact_id) { $res_contact = $contactstatic->fetch($contact_id); $tmparray = $this->get_substitutionarray_contact($contactstatic, $outputlangs, 'contact'); foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlines->merge(); } $odfHandler->mergeSegment($listlines); } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); //return -1; } } // Make substitutions into odt of thirdparty + external modules $tmparray = $this->get_substitutionarray_thirdparty($object, $outputlangs); complete_substitutions_array($tmparray, $outputlangs, $object); // Call the ODTSubstitution hook $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray); $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks // Replace variables into document foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { // setVars failed, probably because key not found } } // Replace labels translated $tmparray = $outputlangs->get_translations_for_substitutions(); foreach ($tmparray as $key => $value) { try { $odfHandler->setVars($key, $value, true, 'UTF-8'); } catch (OdfException $e) { } } // Call the beforeODTSave hook $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { try { $odfHandler->exportAsAttachedPDF($file); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } } else { try { $odfHandler->creator = $user->getFullName($outputlangs); $odfHandler->title = $object->builddoc_filename; $odfHandler->subject = $object->builddoc_filename; if (!empty($conf->global->ODT_ADD_DOLIBARR_ID)) { $odfHandler->userdefined['dol_id'] = $object->id; $odfHandler->userdefined['dol_element'] = $object->element; } $odfHandler->saveToDisk($file); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } } $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } $odfHandler = null; // Destroy object return 1; // Success } else { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } } $this->error = 'UnknownError'; return -1; }