Esempio n. 1
0
llxHeader("", $title, "");
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project');
$param = $mode ? '&mode=' . $mode : '';
// Show navigation bar
$nav = "<a href=\"?year=" . $prev_year . "&amp;month=" . $prev_month . "&amp;day=" . $prev_day . $param . "\">" . img_previous($langs->trans("Previous")) . "</a>\n";
$nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "day") . " </span>\n";
$nav .= "<a href=\"?year=" . $next_year . "&amp;month=" . $next_month . "&amp;day=" . $next_day . $param . "\">" . img_next($langs->trans("Next")) . "</a>\n";
$nav .= " &nbsp; (<a href=\"?year=" . $nowyear . "&amp;month=" . $nowmonth . "&amp;day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a>)";
$nav .= '<br>' . $form->select_date(-1, '', 0, 0, 2, "addtime", 1, 0, 1) . ' ';
$nav .= ' <input type="submit" name="submitdateselect" class="button" value="' . $langs->trans("Refresh") . '">';
$picto = 'calendarweek';
print '<form name="addtime" method="POST" action="' . $_SERVER["PHP_SELF"] . ($project->id > 0 ? '?id=' . $project->id : '') . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="addtime">';
print '<input type="hidden" name="mode" value="' . $mode . '">';
$tmp = dol_getdate($daytoparse);
print '<input type="hidden" name="addtimeyear" value="' . $tmp['year'] . '">';
print '<input type="hidden" name="addtimemonth" value="' . $tmp['mon'] . '">';
print '<input type="hidden" name="addtimeday" value="' . $tmp['mday'] . '">';
$head = project_timesheet_prepare_head($mode);
dol_fiche_head($head, 'inputperday', '', 0, 'task');
// Show description of content
if ($mine) {
    print $langs->trans("MyTasksDesc") . ($onlyopenedproject ? ' ' . $langs->trans("OnlyOpenedProject") : '') . '<br>';
} else {
    if ($user->rights->projet->all->lire && !$socid) {
        print $langs->trans("ProjectsDesc") . ($onlyopenedproject ? ' ' . $langs->trans("OnlyOpenedProject") : '') . '<br>';
    } else {
        print $langs->trans("ProjectsPublicTaskDesc") . ($onlyopenedproject ? ' ' . $langs->trans("AlsoOnlyOpenedProject") : '') . '<br>';
    }
}
Esempio n. 2
0
 print '<td colspan="4">&nbsp;</td>';
 print "</tr>\n";
 $var = true;
 print '<tr ' . $bcnd[$var] . ">\n";
 print '<td>';
 // editeur wysiwyg
 if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
     require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
     $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'alpha'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, 70);
     $doleditor->Create();
 }
 print '</td>';
 // Date intervention
 print '<td align="center" class="nowrap">';
 $now = dol_now();
 $timearray = dol_getdate($now);
 if (!GETPOST('diday', 'int')) {
     $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
 } else {
     $timewithnohour = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
 }
 $form->select_date($timewithnohour, 'di', 1, 1, 0, "addinter");
 print '</td>';
 // Duration
 print '<td align="right">';
 $selectmode = 'select';
 if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
     $selectmode = 'text';
 }
 $form->select_duration('duration', !GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int') ? 3600 : 60 * 60 * GETPOST('durationhour', 'int') + 60 * GETPOST('durationmin', 'int'), 0, $selectmode);
 print '</td>';
 /**
  *
  * Count Facture history
  *
  */
 public static function countHistoricFac()
 {
     global $db, $conf, $user;
     $ret = -1;
     $function = "GetHistoric";
     $sql = 'SELECT (SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******" AND pf.fk_cash IN (";
         $sql2 .= "SELECT pu.fk_terminal FROM " . MAIN_DB_PREFIX . "pos_users as pu WHERE pu.fk_object = " . $_SESSION["uid"] . " AND pu.objtype = 'user'";
         $sql2 .= " UNION SELECT pu.fk_terminal FROM " . MAIN_DB_PREFIX . "pos_users as pu LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ug ON pu.fk_object = ug.fk_usergroup";
         $sql2 .= " WHERE ug.fk_user = "******"uid"] . " AND pu.objtype = 'group')";
     }
     $sql .= $sql2;
     $now = dol_now();
     $time = dol_getdate($now);
     $day = $time['mday'];
     $month = $time['mon'];
     $year = $time['year'];
     //Today
     $todayini = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 0, 0, 0);
     $todayfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $todayini . "' AND '" . $todayfin . "' ) as today, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['day'], 0, 0, 0);
     $yestfin = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['day'], 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $yestini . "' AND '" . $yestfin . "' ) as yesterday, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $time['first_day'], 0, 0, 0);
     $weekfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $weekini . "' AND '" . $weekfin . "' ) as thisweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['prev_year'], $time['prev_month'], $time['prev_day'], 0, 0, 0);
     $lweekfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $time['first_day'] - 1 == 0 ? $time['prev_month'] : $month, $time['first_day'] - 1 == 0 ? $time['prev_day'] + 6 : $time['first_day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $lweekini . "' AND '" . $lweekfin . "' ) as lastweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time2['year'], $time2['month'], $time2['day'], 0, 0, 0);
     $fin2week = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['day'] - 1 == 0 ? $time2['month'] : $time['month'], $time['day'] - 1 == 0 ? $time2['day'] + 6 : $time['day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $ini2week . "' AND '" . $fin2week . "' ) as twoweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time2['year'], $time2['month'], $time2['day'], 0, 0, 0);
     $fin3week = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['day'] - 1 == 0 ? $time2['month'] : $time['month'], $time['day'] - 1 == 0 ? $time2['day'] + 6 : $time['day'] - 1, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $ini3week . "' AND '" . $fin3week . "' ) as threeweek, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $year, $month, 01, 0, 0, 0);
     $monthfin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $monthini . "' AND '" . $monthfin . "' ) as thismonth, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], $day, 0, 0, 0);
     $monthagofin = sprintf("%04d%02d%02d%02d%02d%02d", $year, $month, $day, 23, 59, 59);
     $sql .= " AND f.datec BETWEEN '" . $monthagoini . "' AND '" . $monthagofin . "' ) as monthago, ";
     $sql .= '(SELECT COUNT(f.rowid)';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f';
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " RIGHT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = "******"%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], 01, 0, 0, 0);
     $lmonthfin = sprintf("%04d%02d%02d%02d%02d%02d", $time['year'], $time['month'], 31, 0, 0, 0);
     $sql .= " AND f.datec BETWEEN '" . $lmonthini . "' AND '" . $lmonthfin . "' ) as lastmonth";
     $res = $db->query($sql);
     if ($res) {
         $obj = $db->fetch_object($res);
         $result["today"] = $obj->today;
         $result["yesterday"] = $obj->yesterday;
         $result["thisweek"] = $obj->thisweek;
         $result["lastweek"] = $obj->lastweek;
         $result["twoweek"] = $obj->twoweek;
         $result["threeweek"] = $obj->threeweek;
         $result["thismonth"] = $obj->thismonth;
         $result["monthago"] = $obj->monthago;
         $result["lastmonth"] = $obj->lastmonth;
         return ErrorControl($result, $function);
     } else {
         return ErrorControl($ret, $function);
     }
 }
    /**
     *  Load data into info_box_contents array to show array later.
     *
     *  @param	int		$max        Maximum number of records to load
     *  @return	void
     */
    function loadBox($max = 5)
    {
        global $conf, $user, $langs, $db;
        $this->max = $max;
        $refreshaction = 'refresh_' . $this->boxcode;
        include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
        $text = $langs->trans("BoxSuppliersInvoicesPerMonth", $max);
        $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text), 'graph' => 1, 'sublink' => '', 'subtext' => $langs->trans("Filter"), 'subpicto' => 'filter.png', 'subclass' => 'linkobject', 'target' => 'none');
        $dir = '';
        // We don't need a path because image file will not be saved into disk
        $prefix = '';
        $socid = 0;
        if ($user->societe_id) {
            $socid = $user->societe_id;
        }
        if (!$user->rights->societe->client->voir || $socid) {
            $prefix .= 'private-' . $user->id . '-';
        }
        // If user has no permission to see all, output dir is specific to user
        if ($user->rights->fournisseur->facture->lire) {
            $param_year = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_year';
            $param_shownb = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_shownb';
            $param_showtot = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_showtot';
            include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
            include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php';
            $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
            if (in_array('DOLUSERCOOKIE_box_' . $this->boxcode, $autosetarray)) {
                $endyear = GETPOST($param_year, 'int');
                $shownb = GETPOST($param_shownb, 'alpha');
                $showtot = GETPOST($param_showtot, 'alpha');
            } else {
                $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_' . $this->boxcode], true);
                $endyear = $tmparray['year'];
                $shownb = $tmparray['shownb'];
                $showtot = $tmparray['showtot'];
            }
            if (empty($shownb) && empty($showtot)) {
                $showtot = 1;
            }
            $nowarray = dol_getdate(dol_now(), true);
            if (empty($endyear)) {
                $endyear = $nowarray['year'];
            }
            $startyear = $endyear - 1;
            $mode = 'supplier';
            $WIDTH = $shownb && $showtot || !empty($conf->dol_optimize_smallscreen) ? '256' : '320';
            $HEIGHT = '192';
            $stats = new FactureStats($this->db, $socid, $mode, 0);
            // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
            if ($shownb) {
                $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, GETPOST('action') == $refreshaction ? -1 : 3600 * 24);
                $filenamenb = $dir . "/" . $prefix . "invoicessuppliernbinyear-" . $year . ".png";
                if ($mode == 'customer') {
                    $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-' . $year . '.png';
                }
                if ($mode == 'supplier') {
                    $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-' . $year . '.png';
                }
                $px1 = new DolGraph();
                $mesg = $px1->isGraphKo();
                if (!$mesg) {
                    $px1->SetData($data1);
                    unset($data1);
                    $px1->SetPrecisionY(0);
                    $i = $startyear;
                    $legend = array();
                    while ($i <= $endyear) {
                        $legend[] = $i;
                        $i++;
                    }
                    $px1->SetLegend($legend);
                    $px1->SetMaxValue($px1->GetCeilMaxValue());
                    $px1->SetWidth($WIDTH);
                    $px1->SetHeight($HEIGHT);
                    $px1->SetYLabel($langs->trans("NumberOfBills"));
                    $px1->SetShading(3);
                    $px1->SetHorizTickIncrement(1);
                    $px1->SetPrecisionY(0);
                    $px1->SetCssPrefix("cssboxes");
                    $px1->mode = 'depth';
                    $px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
                    $px1->draw($filenamenb, $fileurlnb);
                }
            }
            // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
            if ($showtot) {
                $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, GETPOST('action') == $refreshaction ? -1 : 3600 * 24);
                $filenamenb = $dir . "/" . $prefix . "invoicessupplieramountinyear-" . $year . ".png";
                if ($mode == 'customer') {
                    $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-' . $year . '.png';
                }
                if ($mode == 'supplier') {
                    $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-' . $year . '.png';
                }
                $px2 = new DolGraph();
                $mesg = $px2->isGraphKo();
                if (!$mesg) {
                    $px2->SetData($data2);
                    unset($data2);
                    $px2->SetPrecisionY(0);
                    $i = $startyear;
                    $legend = array();
                    while ($i <= $endyear) {
                        $legend[] = $i;
                        $i++;
                    }
                    $px2->SetLegend($legend);
                    $px2->SetMaxValue($px2->GetCeilMaxValue());
                    $px2->SetWidth($WIDTH);
                    $px2->SetHeight($HEIGHT);
                    $px2->SetYLabel($langs->trans("AmountOfBillsHT"));
                    $px2->SetShading(3);
                    $px2->SetHorizTickIncrement(1);
                    $px2->SetPrecisionY(0);
                    $px2->SetCssPrefix("cssboxes");
                    $px2->mode = 'depth';
                    $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
                    $px2->draw($filenamenb, $fileurlnb);
                }
            }
            if (empty($conf->use_javascript_ajax)) {
                $langs->load("errors");
                $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
            }
            if (!$mesg) {
                $stringtoshow = '';
                $stringtoshow .= '<script type="text/javascript" language="javascript">
					jQuery(document).ready(function() {
						jQuery("#idsubimg' . $this->boxcode . '").click(function() {
							jQuery("#idfilter' . $this->boxcode . '").toggle();
						});
					});
					</script>';
                $stringtoshow .= '<div class="center hideobject" id="idfilter' . $this->boxcode . '">';
                // hideobject is to start hidden
                $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
                $stringtoshow .= '<input type="hidden" name="action" value="' . $refreshaction . '">';
                $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_' . $this->boxcode . ':year,shownb,showtot">';
                $stringtoshow .= '<input type="checkbox" name="' . $param_shownb . '"' . ($shownb ? ' checked' : '') . '> ' . $langs->trans("NumberOfBillsByMonth");
                $stringtoshow .= ' &nbsp; ';
                $stringtoshow .= '<input type="checkbox" name="' . $param_showtot . '"' . ($showtot ? ' checked' : '') . '> ' . $langs->trans("AmountOfBillsByMonthHT");
                $stringtoshow .= '<br>';
                $stringtoshow .= $langs->trans("Year") . ' <input class="flat" size="4" type="text" name="' . $param_year . '" value="' . $endyear . '">';
                $stringtoshow .= '<input type="image" alt="' . $langs->trans("Refresh") . '" src="' . img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1) . '">';
                $stringtoshow .= '</form>';
                $stringtoshow .= '</div>';
                if ($shownb && $showtot) {
                    $stringtoshow .= '<div class="fichecenter">';
                    $stringtoshow .= '<div class="fichehalfleft">';
                }
                if ($shownb) {
                    $stringtoshow .= $px1->show();
                }
                if ($shownb && $showtot) {
                    $stringtoshow .= '</div>';
                    $stringtoshow .= '<div class="fichehalfright">';
                }
                if ($showtot) {
                    $stringtoshow .= $px2->show();
                }
                if ($shownb && $showtot) {
                    $stringtoshow .= '</div>';
                    $stringtoshow .= '</div>';
                }
                $this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"', 'textnoformat' => $stringtoshow);
            } else {
                $this->info_box_contents[0][0] = array('td' => 'align="left" class="nohover"', 'maxlength' => 500, 'text' => $mesg);
            }
        } else {
            $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed"));
        }
    }
Esempio n. 5
0
if (!$sortfield) {
    $sortfield = "dateevent";
}
$search_code = GETPOST("search_code");
$search_ip = GETPOST("search_ip");
$search_user = GETPOST("search_user");
$search_desc = GETPOST("search_desc");
$search_ua = GETPOST("search_ua");
$date_start = dol_mktime(0, 0, 0, $_REQUEST["date_startmonth"], $_REQUEST["date_startday"], $_REQUEST["date_startyear"]);
$date_end = dol_mktime(23, 59, 59, $_REQUEST["date_endmonth"], $_REQUEST["date_endday"], $_REQUEST["date_endyear"]);
// checks:if date_start>date_end  then date_end=date_start + 24 hours
if ($date_start > $date_end) {
    $date_end = $date_start + 86400;
}
$now = dol_now();
$nowarray = dol_getdate($now);
$params = "&amp;search_code={$search_code}&amp;search_ip={$search_ip}&amp;search_user={$search_user}&amp;search_desc={$search_desc}&amp;search_ua={$search_ua}";
$params .= "&amp;date_startmonth=" . $_REQUEST["date_startmonth"];
$params .= "&amp;date_startday=" . $_REQUEST["date_startday"];
$params .= "&amp;date_startyear=" . $_REQUEST["date_startyear"];
$params .= "&amp;date_endmonth=" . $_REQUEST["date_endmonth"];
$params .= "&amp;date_endday=" . $_REQUEST["date_endday"];
$params .= "&amp;date_endyear=" . $_REQUEST["date_endyear"];
if (empty($date_start)) {
    $date_start = dol_get_first_day($nowarray['year'], $nowarray['mon'], false);
}
if (empty($date_end)) {
    $date_end = dol_mktime(23, 59, 59, $nowarray['mon'], $nowarray['mday'], $nowarray['year']);
}
/*
 * Actions
Esempio n. 6
0
 /**
  *  Initialise an instance with random values.
  *  Used to build previews or test instances.
  *	id must be 0 if object instance is a specimen.
  *
  *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
  *  @return	void
  */
 function initAsSpecimen($option = '')
 {
     global $user, $langs, $conf;
     $now = dol_now();
     $arraynow = dol_getdate($now);
     $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
     $prodids = array();
     $sql = "SELECT rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product";
     $sql .= " WHERE entity IN (" . getEntity('product', 1) . ")";
     $resql = $this->db->query($sql);
     if ($resql) {
         $num_prods = $this->db->num_rows($resql);
         $i = 0;
         while ($i < $num_prods) {
             $i++;
             $row = $this->db->fetch_row($resql);
             $prodids[$i] = $row[0];
         }
     }
     // Initialize parameters
     $this->id = 0;
     $this->ref = 'SPECIMEN';
     $this->specimen = 1;
     $this->socid = 1;
     $this->date = $nownotime;
     $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
     $this->cond_reglement_id = 1;
     $this->cond_reglement_code = 'RECEP';
     $this->date_lim_reglement = $this->calculate_date_lim_reglement();
     $this->mode_reglement_id = 0;
     // Not forced to show payment mode CHQ + VIR
     $this->mode_reglement_code = '';
     // Not forced to show payment mode CHQ + VIR
     $this->note_public = 'This is a comment (public)';
     $this->note_private = 'This is a comment (private)';
     $this->note = 'This is a comment (private)';
     $this->fk_incoterms = 0;
     $this->location_incoterms = '';
     if (empty($option) || $option != 'nolines') {
         // Lines
         $nbp = 5;
         $xnbp = 0;
         while ($xnbp < $nbp) {
             $line = new FactureLigne($this->db);
             $line->desc = $langs->trans("Description") . " " . $xnbp;
             $line->qty = 1;
             $line->subprice = 100;
             $line->tva_tx = 19.6;
             $line->localtax1_tx = 0;
             $line->localtax2_tx = 0;
             $line->remise_percent = 0;
             if ($xnbp == 1) {
                 $prodid = rand(1, $num_prods);
                 $line->fk_product = $prodids[$prodid];
                 $line->qty = -1;
                 $line->total_ht = -100;
                 $line->total_ttc = -119.6;
                 $line->total_tva = -19.6;
             } else {
                 if ($xnbp == 2) {
                     $line->subprice = -100;
                     $line->total_ht = -100;
                     $line->total_ttc = -119.6;
                     $line->total_tva = -19.6;
                     $line->remise_percent = 0;
                 } else {
                     if ($xnbp == 3) {
                         $prodid = rand(1, $num_prods);
                         $line->fk_product = $prodids[$prodid];
                         $line->total_ht = 50;
                         $line->total_ttc = 59.8;
                         $line->total_tva = 9.800000000000001;
                         $line->remise_percent = 50;
                     } else {
                         $prodid = rand(1, $num_prods);
                         $line->fk_product = $prodids[$prodid];
                         $line->total_ht = 100;
                         $line->total_ttc = 119.6;
                         $line->total_tva = 19.6;
                         $line->remise_percent = 00;
                     }
                 }
             }
             $this->lines[$xnbp] = $line;
             $xnbp++;
             $this->total_ht += $line->total_ht;
             $this->total_tva += $line->total_tva;
             $this->total_ttc += $line->total_ttc;
         }
         $this->revenuestamp = 0;
         // Add a line "offered"
         $line = new FactureLigne($this->db);
         $line->desc = $langs->trans("Description") . " (offered line)";
         $line->qty = 1;
         $line->subprice = 100;
         $line->tva_tx = 19.6;
         $line->localtax1_tx = 0;
         $line->localtax2_tx = 0;
         $line->remise_percent = 100;
         $line->total_ht = 0;
         $line->total_ttc = 0;
         // 90 * 1.196
         $line->total_tva = 0;
         $prodid = rand(1, $num_prods);
         $line->fk_product = $prodids[$prodid];
         $this->lines[$xnbp] = $line;
         $xnbp++;
     }
 }
Esempio n. 7
0
 /**
  *  Initialise an instance with random values.
  *  Used to build previews or test instances.
  *	id must be 0 if object instance is a specimen.
  *
  *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
  *  @return	void
  */
 function initAsSpecimen($option = '')
 {
     global $user, $langs, $conf;
     $now = dol_now();
     $arraynow = dol_getdate($now);
     $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
     // Initialize parameters
     $this->id = 0;
     $this->ref = 'SPECIMEN';
     $this->specimen = 1;
     $this->facid = 1;
     $this->datepaye = $nownotime;
 }
Esempio n. 8
0
/**	Return first day of week for a date. First day of week may be monday if option MAIN_START_WEEK is 1.
 *
 *	@param		int		$day		Day
 * 	@param		int		$month		Month
 *  @param		int		$year		Year
 * 	@param		int		$gm			False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
 *	@return		array				year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year
 */
function dol_get_first_day_week($day, $month, $year, $gm = false)
{
    global $conf;
    //$day=2; $month=2; $year=2015;
    $date = dol_mktime(0, 0, 0, $month, $day, $year, $gm);
    //Checking conf of start week
    $start_week = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1;
    $tmparray = dol_getdate($date, true);
    // detail of current day
    //Calculate days = offset from current day
    $days = $start_week - $tmparray['wday'];
    if ($days >= 1) {
        $days = 7 - $days;
    }
    $days = abs($days);
    $seconds = $days * 24 * 60 * 60;
    //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>';
    //Get first day of week
    $tmpdaytms = date($tmparray[0]) - $seconds;
    // $tmparray[0] is day of parameters
    $tmpday = date("d", $tmpdaytms);
    //Check first day of week is in same month than current day or not
    if ($tmpday > $day) {
        $prev_month = $month - 1;
        $prev_year = $year;
        if ($prev_month == 0) {
            $prev_month = 12;
            $prev_year = $year - 1;
        }
    } else {
        $prev_month = $month;
        $prev_year = $year;
    }
    $tmpmonth = $prev_month;
    $tmpyear = $prev_year;
    //Get first day of next week
    $tmptime = dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
    $tmptime -= 24 * 60 * 60 * 7;
    $tmparray = dol_getdate($tmptime, true);
    $prev_day = $tmparray['mday'];
    //Check prev day of week is in same month than first day or not
    if ($prev_day > $tmpday) {
        $prev_month = $month - 1;
        $prev_year = $year;
        if ($prev_month == 0) {
            $prev_month = 12;
            $prev_year = $year - 1;
        }
    }
    $week = date("W", dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
    return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day);
}
 /**
  *  Show list of actions for element
  *
  *  @param	Object	$object			Object
  *  @param  string	$typeelement	'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
  *	@param	int		$socid			socid of user
  *  @param	int		$forceshowtitle	Show title even if there is no actions to show
  *	@return	int						<0 if KO, >=0 if OK
  */
 function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0)
 {
     global $langs, $conf, $user;
     global $bc;
     require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
     $listofactions = ActionComm::getActions($this->db, $socid, $object->id, $typeelement);
     if (!is_array($listofactions)) {
         dol_print_error($this->db, 'FailedToGetActions');
     }
     $num = count($listofactions);
     if ($num || $forceshowtitle) {
         if ($typeelement == 'invoice') {
             $title = $langs->trans('ActionsOnBill');
         } elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') {
             $title = $langs->trans('ActionsOnBill');
         } elseif ($typeelement == 'propal') {
             $title = $langs->trans('ActionsOnPropal');
         } elseif ($typeelement == 'supplier_proposal') {
             $title = $langs->trans('ActionsOnSupplierProposal');
         } elseif ($typeelement == 'order') {
             $title = $langs->trans('ActionsOnOrder');
         } elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') {
             $title = $langs->trans('ActionsOnOrder');
         } elseif ($typeelement == 'project') {
             $title = $langs->trans('ActionsOnProject');
         } elseif ($typeelement == 'shipping') {
             $title = $langs->trans('ActionsOnShipping');
         } elseif ($typeelement == 'fichinter') {
             $title = $langs->trans('ActionsOnFicheInter');
         } else {
             $title = $langs->trans("Actions");
         }
         print load_fiche_titre($title, '', '');
         $total = 0;
         $var = true;
         print '<table class="noborder" width="100%">';
         print '<tr class="liste_titre">';
         print '<th class="liste_titre">' . $langs->trans('Ref') . '</th>';
         print '<th class="liste_titre">' . $langs->trans('Action') . '</th>';
         print '<th class="liste_titre">' . $langs->trans('Date') . '</th>';
         print '<th class="liste_titre">' . $langs->trans('By') . '</th>';
         print '<th class="liste_titre" align="right">' . $langs->trans('Status') . '</th>';
         print '</tr>';
         print "\n";
         $userstatic = new User($this->db);
         foreach ($listofactions as $action) {
             $ref = $action->getNomUrl(1, -1);
             $label = $action->getNomUrl(0, 38);
             $var = !$var;
             print '<tr ' . $bc[$var] . '>';
             print '<td>' . $ref . '</td>';
             print '<td>' . $label . '</td>';
             print '<td>' . dol_print_date($action->datep, 'dayhour');
             if ($action->datef) {
                 $tmpa = dol_getdate($action->datep);
                 $tmpb = dol_getdate($action->datef);
                 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
                     if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) {
                         print '-' . dol_print_date($action->datef, 'hour');
                     }
                 } else {
                     print '-' . dol_print_date($action->datef, 'dayhour');
                 }
             }
             print '</td>';
             print '<td>';
             if (!empty($action->author->id)) {
                 $userstatic->id = $action->author->id;
                 $userstatic->firstname = $action->author->firstname;
                 $userstatic->lastname = $action->author->lastname;
                 print $userstatic->getNomUrl(1);
             }
             print '</td>';
             print '<td align="right">';
             if (!empty($action->author->id)) {
                 print $action->getLibStatut(3);
             }
             print '</td>';
             print '</tr>';
         }
         print '</table>';
     }
     return $num;
 }
Esempio n. 10
0
/**
 * Output a task line into a perday intput mode
 *
 * @param	string	   	$inc					Line number (start to 0, then increased by recursive call)
 * @param	int			$firstdaytoshow			First day to show
 * @param	User|null	$fuser					Restrict list to user if defined
 * @param   string		$parent					Id of parent project to show (0 to show all)
 * @param   Task[]		$lines					Array of lines
 * @param   int			$level					Level (start to 0, then increased/decrease by recursive call)
 * @param   string		$projectsrole			Array of roles user has on project
 * @param   string		$tasksrole				Array of roles user has on task
 * @param	string		$mine					Show only task lines I am assigned to
 * @param   int			$restricteditformytask	0=No restriction, 1=Enable add time only if task is a task i am affected to
 * @return  $inc
 */
function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask = 1)
{
    global $db, $user, $bc, $langs;
    global $form, $formother, $projectstatic, $taskstatic;
    $lastprojectid = 0;
    $var = true;
    $numlines = count($lines);
    for ($i = 0; $i < $numlines; $i++) {
        if ($parent == 0) {
            $level = 0;
        }
        if ($lines[$i]->fk_parent == $parent) {
            // Break on a new project
            if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
                $var = !$var;
                $lastprojectid = $lines[$i]->fk_project;
                $projectstatic->id = $lines[$i]->fk_project;
                $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id);
                // Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTaks for all day of a week
            }
            // If we want all or we have a role on task, we show it
            if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
                print "<tr " . $bc[$var] . ">\n";
                // Project
                print '<td class="nowrap">';
                $projectstatic->id = $lines[$i]->fk_project;
                $projectstatic->ref = $lines[$i]->projectref;
                $projectstatic->title = $lines[$i]->projectlabel;
                $projectstatic->public = $lines[$i]->public;
                print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole") . ': ' . $projectsrole[$lines[$i]->fk_project]);
                print "</td>";
                // Ref
                print '<td class="nowrap">';
                $taskstatic->id = $lines[$i]->id;
                $taskstatic->ref = $lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id;
                print $taskstatic->getNomUrl(1, 'withproject', 'time');
                print '</td>';
                // Label task
                print "<td>";
                print '<!-- Task id = ' . $lines[$i]->id . ' -->';
                for ($k = 0; $k < $level; $k++) {
                    print "&nbsp;&nbsp;&nbsp;";
                }
                $taskstatic->id = $lines[$i]->id;
                $taskstatic->ref = $lines[$i]->label;
                $taskstatic->date_start = $lines[$i]->date_start;
                $taskstatic->date_end = $lines[$i]->date_end;
                print $taskstatic->getNomUrl(0, 'withproject', 'time');
                //print "<br>";
                //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
                //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
                print "</td>\n";
                // Planned Workload
                print '<td align="right">';
                if ($lines[$i]->planned_workload) {
                    print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
                } else {
                    print '--:--';
                }
                print '</td>';
                // Progress declared %
                print '<td align="right">';
                print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
                print '</td>';
                // Time spent by everybody
                print '<td align="right">';
                // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
                if ($lines[$i]->duration) {
                    print '<a href="' . DOL_URL_ROOT . '/projet/tasks/time.php?id=' . $lines[$i]->id . '">';
                    print convertSecondToTime($lines[$i]->duration, 'allhourmin');
                    print '</a>';
                } else {
                    print '--:--';
                }
                print "</td>\n";
                // Time spent by user
                print '<td align="right">';
                $tmptimespent = $taskstatic->getSummaryOfTimeSpent();
                if ($tmptimespent['total_duration']) {
                    print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
                } else {
                    print '--:--';
                }
                print "</td>\n";
                $disabledproject = 1;
                $disabledtask = 1;
                //print "x".$lines[$i]->fk_project;
                //var_dump($lines[$i]);
                //var_dump($projectsrole[$lines[$i]->fk_project]);
                // If at least one role for project
                if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
                    $disabledproject = 0;
                    $disabledtask = 0;
                }
                // If $restricteditformytask is on and I have no role on task, i disable edit
                if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
                    $disabledtask = 1;
                }
                //var_dump($projectstatic->weekWorkLoadPerTask);
                // Fields to show current time
                $tableCell = '';
                $modeinput = 'hours';
                for ($idw = 0; $idw < 7; $idw++) {
                    $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
                    $tmparray = dol_getdate($tmpday);
                    $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
                    $alreadyspent = '';
                    if ($dayWorkLoad > 0) {
                        $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
                    }
                    $alttitle = $langs->trans("AddHereTimeSpentForDay", $tmparray['day'], $tmparray['mon']);
                    $tableCell = '<td align="center" class="hide' . $idw . '">';
                    if ($alreadyspent) {
                        $tableCell .= '<span class="timesheetalreadyrecorded"><input type="text" class="center smallpadd" size="2" disabled id="timespent[' . $inc . '][' . $idw . ']" name="task[' . $lines[$i]->id . '][' . $idw . ']" value="' . $alreadyspent . '"></span>';
                        //$placeholder=' placeholder="00:00"';
                        $placeholder = '';
                        //$tableCell.='+';
                    }
                    $tableCell .= '<input type="text" alt="' . ($disabledtask ? '' : $alttitle) . '" title="' . ($disabledtask ? '' : $alttitle) . '" ' . ($disabledtask ? 'disabled' : $placeholder) . ' class="center smallpadd" size="2" id="timeadded[' . $inc . '][' . $idw . ']" name="task[' . $lines[$i]->id . '][' . $idw . ']" value="" cols="2"  maxlength="5"';
                    $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
                    $tableCell .= 'onblur="regexEvent(this,event,\'' . $modeinput . '\'); updateTotal(' . $idw . ',\'' . $modeinput . '\')" />';
                    $tableCell .= '</td>';
                    print $tableCell;
                }
                print '<td align="right">';
                if (!$lines[$i]->public && $disabledproject) {
                    print $form->textwithpicto('', $langs->trans("YouAreNotContactOfProject"));
                } else {
                    if ($disabledtask) {
                        print $form->textwithpicto('', $langs->trans("TaskIsNotAffectedToYou"));
                    }
                }
                print '</td>';
                print "</tr>\n";
            }
            $inc++;
            $level++;
            if ($lines[$i]->id) {
                projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
            }
            $level--;
        } else {
            //$level--;
        }
    }
    return $inc;
}
Esempio n. 11
0
 /**
  *  Initialise an instance with random values.
  *  Used to build previews or test instances.
  *	id must be 0 if object instance is a specimen.
  *
  *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
  *  @return	void
  */
 function initAsSpecimen($option = '')
 {
     global $user, $langs, $conf;
     $now = dol_now();
     $arraynow = dol_getdate($now);
     $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
     parent::initAsSpecimen($option);
     $this->usenewprice = 1;
 }
Esempio n. 12
0
/**
 *    	Show html area with actions done
 *
 * 		@param	Conf		$conf		Object conf
 * 		@param	Translate	$langs		Object langs
 * 		@param	DoliDB		$db			Object db
 * 		@param	Adherent|Societe		$object		Object third party or member
 * 		@param	Contact		$objcon		Object contact
 *      @param  int			$noprint    Return string but does not output it
 *      @return	mixed					Return html part or void if noprint is 1
 * TODO change function to be able to list event linked to an object.
 */
function show_actions_done($conf, $langs, $db, $object, $objcon = '', $noprint = 0)
{
    global $bc, $user, $conf;
    // Check parameters
    if (!is_object($object)) {
        dol_print_error('', 'BadParameter');
    }
    $out = '';
    $histo = array();
    $numaction = 0;
    $now = dol_now('tzuser');
    if (!empty($conf->agenda->enabled)) {
        // Recherche histo sur actioncomm
        $sql = "SELECT a.id, a.label,";
        $sql .= " a.datep as dp,";
        $sql .= " a.datep2 as dp2,";
        $sql .= " a.note, a.percent,";
        $sql .= " a.fk_element, a.elementtype,";
        $sql .= " a.fk_user_author, a.fk_contact,";
        $sql .= " c.code as acode, c.libelle,";
        $sql .= " u.login, u.rowid as user_id";
        if (get_class($object) == 'Societe') {
            $sql .= ", sp.lastname, sp.firstname";
        }
        if (get_class($object) == 'Adherent') {
            $sql .= ", m.lastname, m.firstname";
        }
        $sql .= " FROM " . MAIN_DB_PREFIX . "user as u, " . MAIN_DB_PREFIX . "actioncomm as a";
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_actioncomm as c ON a.fk_action = c.id";
        if (get_class($object) == 'Societe') {
            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
        }
        if (get_class($object) == 'Adherent') {
            $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
        }
        $sql .= " WHERE u.rowid = a.fk_user_author";
        $sql .= " AND a.entity IN (" . getEntity('agenda', 1) . ")";
        if (get_class($object) == 'Societe' && $object->id) {
            $sql .= " AND a.fk_soc = " . $object->id;
        }
        if (get_class($object) == 'Adherent') {
            $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
        }
        if (get_class($object) == 'Adherent' && $object->id) {
            $sql .= " AND a.fk_element = " . $object->id;
        }
        if (is_object($objcon) && $objcon->id) {
            $sql .= " AND a.fk_contact = " . $objcon->id;
        }
        $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))";
        $sql .= " ORDER BY a.datep DESC, a.id DESC";
        dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
        $resql = $db->query($sql);
        if ($resql) {
            $i = 0;
            $num = $db->num_rows($resql);
            $var = true;
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $histo[$numaction] = array('type' => 'action', 'id' => $obj->id, 'datestart' => $db->jdate($obj->dp), 'dateend' => $db->jdate($obj->dp2), 'note' => $obj->label, 'percent' => $obj->percent, 'acode' => $obj->acode, 'libelle' => $obj->libelle, 'userid' => $obj->user_id, 'login' => $obj->login, 'contact_id' => $obj->fk_contact, 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'fk_element' => $obj->fk_element, 'elementtype' => $obj->elementtype);
                $numaction++;
                $i++;
            }
        } else {
            dol_print_error($db);
        }
    }
    if (!empty($conf->mailing->enabled) && !empty($objcon->email)) {
        $langs->load("mails");
        // Recherche histo sur mailing
        $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
        $sql .= " 'AC_EMAILING' as acode,";
        $sql .= " u.rowid as user_id, u.login";
        // User that valid action
        $sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u";
        $sql .= " WHERE mc.email = '" . $db->escape($objcon->email) . "'";
        // Search is done on email.
        $sql .= " AND mc.statut = 1";
        $sql .= " AND u.rowid = m.fk_user_valid";
        $sql .= " AND mc.fk_mailing=m.rowid";
        $sql .= " ORDER BY mc.date_envoi DESC, m.rowid DESC";
        dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
        $resql = $db->query($sql);
        if ($resql) {
            $i = 0;
            $num = $db->num_rows($resql);
            $var = true;
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $histo[$numaction] = array('type' => 'mailing', 'id' => $obj->id, 'datestart' => $db->jdate($obj->da), 'dateend' => $db->jdate($obj->da), 'note' => $obj->note, 'percent' => $obj->percentage, 'acode' => $obj->acode, 'userid' => $obj->user_id, 'login' => $obj->login);
                $numaction++;
                $i++;
            }
            $db->free($resql);
        } else {
            dol_print_error($db);
        }
    }
    if (!empty($conf->agenda->enabled) || !empty($conf->mailing->enabled) && !empty($objcon->email)) {
        require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
        require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
        require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
        require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
        $actionstatic = new ActionComm($db);
        $userstatic = new User($db);
        $contactstatic = new Contact($db);
        // TODO uniformize
        $propalstatic = new Propal($db);
        $orderstatic = new Commande($db);
        $facturestatic = new Facture($db);
        $out .= "\n";
        $out .= '<table class="noborder" width="100%">';
        $out .= '<tr class="liste_titre">';
        if ($conf->global->AGENDA_USE_EVENT_TYPE) {
            $out .= '<td colspan="3">';
        } else {
            $out .= '<td colspan="2">';
        }
        if (get_class($object) == 'Societe') {
            $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/listactions.php?socid=' . $object->id . '&amp;status=done">';
        }
        $out .= $langs->trans("ActionsDoneShort");
        if (get_class($object) == 'Societe') {
            $out .= '</a>';
        }
        $out .= '</td>';
        if ($conf->global->AGENDA_USE_EVENT_TYPE) {
            $out .= '<td>';
            $out .= $langs->trans("Type");
            $out .= '</td>';
            $out .= '<td colspan="4" align="right">';
        } else {
            $out .= '<td colspan="5" align="right">';
        }
        $out .= '</td>';
        $out .= '</tr>';
        foreach ($histo as $key => $value) {
            $var = !$var;
            $out .= "<tr " . $bc[$var] . ">";
            $actionstatic->fetch($histo[$key]['id']);
            // Champ date
            $out .= '<td width="120" class="nowrap">';
            $out .= dol_print_date($histo[$key]['datestart'], 'dayhour');
            if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
                $tmpa = dol_getdate($histo[$key]['datestart'], true);
                $tmpb = dol_getdate($histo[$key]['dateend'], true);
                if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
                    $out .= '-' . dol_print_date($histo[$key]['dateend'], 'hour');
                } else {
                    $out .= '-' . dol_print_date($histo[$key]['dateend'], 'dayhour');
                }
            }
            $out .= "</td>\n";
            // Picto
            $out .= '<td width="16">&nbsp;</td>';
            // Action
            $out .= '<td>';
            if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
                $actionstatic->type_code = $histo[$key]['acode'];
                $transcode = $langs->trans("Action" . $histo[$key]['acode']);
                $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : $histo[$key]['libelle'];
                //$actionstatic->libelle=$libelle;
                $actionstatic->libelle = $histo[$key]['note'];
                $actionstatic->id = $histo[$key]['id'];
                $out .= $actionstatic->getNomUrl(1, 120);
            }
            if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
                $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
                $transcode = $langs->trans("Action" . $histo[$key]['acode']);
                $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing';
                $out .= dol_trunc($libelle, 120);
            }
            $out .= '</td>';
            if ($conf->global->AGENDA_USE_EVENT_TYPE) {
                $out .= '<td>';
                $out .= $actionstatic->type;
                $out .= '</td>';
            }
            // Title of event
            //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
            // Objet lie
            // TODO uniformize
            $out .= '<td>';
            //var_dump($histo[$key]['elementtype']);
            if (isset($histo[$key]['elementtype'])) {
                if ($histo[$key]['elementtype'] == 'propal' && !empty($conf->propal->enabled)) {
                    //$propalstatic->ref=$langs->trans("ProposalShort");
                    //$propalstatic->id=$histo[$key]['fk_element'];
                    if ($propalstatic->fetch($histo[$key]['fk_element']) > 0) {
                        $propalstatic->type = $histo[$key]['ftype'];
                        $out .= $propalstatic->getNomUrl(1);
                    } else {
                        $out .= $langs->trans("ProposalDeleted");
                    }
                } elseif (($histo[$key]['elementtype'] == 'order' || $histo[$key]['elementtype'] == 'commande') && !empty($conf->commande->enabled)) {
                    //$orderstatic->ref=$langs->trans("Order");
                    //$orderstatic->id=$histo[$key]['fk_element'];
                    if ($orderstatic->fetch($histo[$key]['fk_element']) > 0) {
                        $orderstatic->type = $histo[$key]['ftype'];
                        $out .= $orderstatic->getNomUrl(1);
                    } else {
                        $out .= $langs->trans("OrderDeleted");
                    }
                } elseif (($histo[$key]['elementtype'] == 'invoice' || $histo[$key]['elementtype'] == 'facture') && !empty($conf->facture->enabled)) {
                    //$facturestatic->ref=$langs->trans("Invoice");
                    //$facturestatic->id=$histo[$key]['fk_element'];
                    if ($facturestatic->fetch($histo[$key]['fk_element']) > 0) {
                        $facturestatic->type = $histo[$key]['ftype'];
                        $out .= $facturestatic->getNomUrl(1, 'compta');
                    } else {
                        $out .= $langs->trans("InvoiceDeleted");
                    }
                } else {
                    $out .= '&nbsp;';
                }
            } else {
                $out .= '&nbsp;';
            }
            $out .= '</td>';
            // Contact pour cette action
            if (!empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
                $contactstatic->lastname = $histo[$key]['lastname'];
                $contactstatic->firstname = $histo[$key]['firstname'];
                $contactstatic->id = $histo[$key]['contact_id'];
                $out .= '<td width="120">' . $contactstatic->getNomUrl(1, '', 10) . '</td>';
            } else {
                $out .= '<td>&nbsp;</td>';
            }
            // Auteur
            $out .= '<td class="nowrap" width="80">';
            //$userstatic->id=$histo[$key]['userid'];
            //$userstatic->login=$histo[$key]['login'];
            //$out.=$userstatic->getLoginUrl(1);
            $userstatic->fetch($histo[$key]['userid']);
            $out .= $userstatic->getNomUrl(1);
            $out .= '</td>';
            // Statut
            $out .= '<td class="nowrap" width="20">' . $actionstatic->LibStatut($histo[$key]['percent'], 3) . '</td>';
            $out .= "</tr>\n";
            $i++;
        }
        $out .= "</table>\n";
        $out .= "<br>\n";
    }
    if ($noprint) {
        return $out;
    } else {
        print $out;
    }
}
Esempio n. 13
0
 /**
  *	Show a HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes.
  *  Fields are preselected with :
  *            	- set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM')
  *            	- local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location)
  *            	- Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1)
  *
  *	@param	timestamp	$set_time 		Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date.
  *	@param	string		$prefix			Prefix for fields name
  *	@param	int			$h				1=Show also hours
  *	@param	int			$m				1=Show also minutes
  *	@param	int			$empty			0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only
  *	@param	string		$form_name 		Not used
  *	@param	int			$d				1=Show days, month, years
  * 	@param	int			$addnowlink		Add a link "Now"
  * 	@param	int			$nooutput		Do not output html string but return it
  * 	@param 	int			$disabled		Disable input fields
  *  @param  int			$fullday        When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59
  *  @param	string		$addplusone		Add a link "+1 hour". Value must be name of another select_date field.
  *  @param  datetime    $adddateof      Add a link "Date of invoice" using the following date.
  * 	@return	mixed						Nothing or string if nooutput is 1
  *  @see	form_date
  */
 function select_date($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $nooutput = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '')
 {
     global $conf, $langs;
     $retstring = '';
     if ($prefix == '') {
         $prefix = 're';
     }
     if ($h == '') {
         $h = 0;
     }
     if ($m == '') {
         $m = 0;
     }
     $emptydate = 0;
     $emptyhours = 0;
     if ($empty == 1) {
         $emptydate = 1;
         $emptyhours = 1;
     }
     if ($empty == 2) {
         $emptydate = 0;
         $emptyhours = 1;
     }
     $orig_set_time = $set_time;
     if ($set_time === '' && $emptydate == 0) {
         include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
         $set_time = dol_now('tzuser') - getServerTimeZoneInt('now') * 3600;
         // set_time must be relative to PHP server timezone
     }
     // Analysis of the pre-selection date
     if (preg_match('/^([0-9]+)\\-([0-9]+)\\-([0-9]+)\\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
         // Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
         $syear = !empty($reg[1]) ? $reg[1] : '';
         $smonth = !empty($reg[2]) ? $reg[2] : '';
         $sday = !empty($reg[3]) ? $reg[3] : '';
         $shour = !empty($reg[4]) ? $reg[4] : '';
         $smin = !empty($reg[5]) ? $reg[5] : '';
     } elseif (strval($set_time) != '' && $set_time != -1) {
         // set_time est un timestamps (0 possible)
         $syear = dol_print_date($set_time, "%Y");
         $smonth = dol_print_date($set_time, "%m");
         $sday = dol_print_date($set_time, "%d");
         if ($orig_set_time != '') {
             $shour = dol_print_date($set_time, "%H");
             $smin = dol_print_date($set_time, "%M");
         }
     } else {
         // Date est '' ou vaut -1
         $syear = '';
         $smonth = '';
         $sday = '';
         $shour = '';
         $smin = '';
     }
     $usecalendar = 'combo';
     if (!empty($conf->use_javascript_ajax) && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR != "none")) {
         $usecalendar = empty($conf->global->MAIN_POPUP_CALENDAR) ? 'eldy' : $conf->global->MAIN_POPUP_CALENDAR;
     }
     if ($conf->browser->phone) {
         $usecalendar = 'combo';
     }
     if ($d) {
         // Show date with popup
         if ($usecalendar != 'combo') {
             $formated_date = '';
             //print "e".$set_time." t ".$conf->format_date_short;
             if (strval($set_time) != '' && $set_time != -1) {
                 //$formated_date=dol_print_date($set_time,$conf->format_date_short);
                 $formated_date = dol_print_date($set_time, $langs->trans("FormatDateShortInput"));
                 // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
             }
             // Calendrier popup version eldy
             if ($usecalendar == "eldy") {
                 // Zone de saisie manuelle de la date
                 $retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" size="9" maxlength="11" value="' . $formated_date . '"';
                 $retstring .= $disabled ? ' disabled' : '';
                 $retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\'); "';
                 // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
                 $retstring .= '>';
                 // Icone calendrier
                 if (!$disabled) {
                     $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons"';
                     $base = DOL_URL_ROOT . '/core/';
                     $retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\',\'' . $langs->defaultlang . '\');">' . img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"') . '</button>';
                 } else {
                     $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>';
                 }
                 $retstring .= '<input type="hidden" id="' . $prefix . 'day"   name="' . $prefix . 'day"   value="' . $sday . '">' . "\n";
                 $retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . "\n";
                 $retstring .= '<input type="hidden" id="' . $prefix . 'year"  name="' . $prefix . 'year"  value="' . $syear . '">' . "\n";
             } else {
                 print "Bad value of MAIN_POPUP_CALENDAR";
             }
         } else {
             //$retstring.='<div class="inline-block">';
             // Day
             $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat" id="' . $prefix . 'day" name="' . $prefix . 'day">';
             if ($emptydate || $set_time == -1) {
                 $retstring .= '<option value="0" selected>&nbsp;</option>';
             }
             for ($day = 1; $day <= 31; $day++) {
                 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
             }
             $retstring .= "</select>";
             $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat" id="' . $prefix . 'month" name="' . $prefix . 'month">';
             if ($emptydate || $set_time == -1) {
                 $retstring .= '<option value="0" selected>&nbsp;</option>';
             }
             // Month
             for ($month = 1; $month <= 12; $month++) {
                 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
                 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
                 $retstring .= "</option>";
             }
             $retstring .= "</select>";
             // Year
             if ($emptydate || $set_time == -1) {
                 $retstring .= '<input' . ($disabled ? ' disabled' : '') . ' placeholder="' . dol_escape_htmltag($langs->trans("Year")) . '" class="flat" type="text" size="3" maxlength="4" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">';
             } else {
                 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat" id="' . $prefix . 'year" name="' . $prefix . 'year">';
                 for ($year = $syear - 5; $year < $syear + 10; $year++) {
                     $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
                 }
                 $retstring .= "</select>\n";
             }
             //$retstring.='</div>';
         }
     }
     if ($d && $h) {
         $retstring .= '&nbsp;';
     }
     if ($h) {
         // Show hour
         $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat ' . ($fullday ? $fullday . 'hour' : '') . '" id="' . $prefix . 'hour" name="' . $prefix . 'hour">';
         if ($emptyhours) {
             $retstring .= '<option value="-1">&nbsp;</option>';
         }
         for ($hour = 0; $hour < 24; $hour++) {
             if (strlen($hour) < 2) {
                 $hour = "0" . $hour;
             }
             $retstring .= '<option value="' . $hour . '"' . ($hour == $shour ? ' selected' : '') . '>' . $hour . (empty($conf->dol_optimize_smallscreen) ? '' : 'H') . '</option>';
         }
         $retstring .= '</select>';
         if ($m && empty($conf->dol_optimize_smallscreen)) {
             $retstring .= ":";
         }
     }
     if ($m) {
         // Show minutes
         $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat ' . ($fullday ? $fullday . 'min' : '') . '" id="' . $prefix . 'min" name="' . $prefix . 'min">';
         if ($emptyhours) {
             $retstring .= '<option value="-1">&nbsp;</option>';
         }
         for ($min = 0; $min < 60; $min++) {
             if (strlen($min) < 2) {
                 $min = "0" . $min;
             }
             $retstring .= '<option value="' . $min . '"' . ($min == $smin ? ' selected' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>';
         }
         $retstring .= '</select>';
     }
     // Add a "Now" link
     if ($conf->use_javascript_ajax && $addnowlink) {
         // Script which will be inserted in the onClick of the "Now" link
         $reset_scripts = "";
         // Generate the date part, depending on the use or not of the javascript calendar
         $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date(dol_now(), 'day') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date(dol_now(), '%d') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date(dol_now(), '%m') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date(dol_now(), '%Y') . '\');';
         /*if ($usecalendar == "eldy")
           {
               $base=DOL_URL_ROOT.'/core/';
               $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\',\''.$langs->defaultlang.'\');';
           }
           else
           {
               $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
               $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
               $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
           }*/
         // Update the hour part
         if ($h) {
             if ($fullday) {
                 $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
             }
             //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
             $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // Update the minute part
         if ($m) {
             if ($fullday) {
                 $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
             }
             //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
             $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
         if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
             $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonNow" type="button" name="_useless" value="now" onClick="' . $reset_scripts . '">';
             $retstring .= $langs->trans("Now");
             $retstring .= '</button> ';
         }
     }
     // Add a "Plus one hour" link
     if ($conf->use_javascript_ajax && $addplusone) {
         // Script which will be inserted in the onClick of the "Add plusone" link
         $reset_scripts = "";
         // Generate the date part, depending on the use or not of the javascript calendar
         $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date(dol_now(), 'day') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date(dol_now(), '%d') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date(dol_now(), '%m') . '\');';
         $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date(dol_now(), '%Y') . '\');';
         // Update the hour part
         if ($h) {
             if ($fullday) {
                 $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
             }
             $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // Update the minute part
         if ($m) {
             if ($fullday) {
                 $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
             }
             $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
         if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
             $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonPlusOne" type="button" name="_useless2" value="plusone" onClick="' . $reset_scripts . '">';
             $retstring .= $langs->trans("DateStartPlusOne");
             $retstring .= '</button> ';
         }
     }
     // Add a "Plus one hour" link
     if ($conf->use_javascript_ajax && $adddateof) {
         $tmparray = dol_getdate($adddateof);
         $retstring .= ' - <button class="dpInvisibleButtons datenowlink" id="dateofinvoice" type="button" name="_dateofinvoice" value="now" onclick="jQuery(\'#re\').val(\'' . dol_print_date($adddateof, 'day') . '\');jQuery(\'#reday\').val(\'' . $tmparray['mday'] . '\');jQuery(\'#remonth\').val(\'' . $tmparray['mon'] . '\');jQuery(\'#reyear\').val(\'' . $tmparray['year'] . '\');">' . $langs->trans("DateInvoice") . '</a>';
     }
     if (!empty($nooutput)) {
         return $retstring;
     }
     print $retstring;
     return;
 }
    /**
     *  Load data into info_box_contents array to show array later.
     *
     *  @param	int		$max        Maximum number of records to load
     *  @return	void
     */
    function loadBox($max = 5)
    {
        global $conf, $user, $langs, $db;
        $this->max = $max;
        $refreshaction = 'refresh_' . $this->boxcode;
        include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
        include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
        include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
        $text = $langs->trans("BoxProductDistribution", $max);
        $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text), 'graph' => 1, 'sublink' => '', 'subtext' => $langs->trans("Filter"), 'subpicto' => 'filter.png', 'subclass' => 'linkobject', 'target' => 'none');
        $param_year = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_year';
        $param_showinvoicenb = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_showinvoicenb';
        $param_showpropalnb = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_showpropalnb';
        $param_showordernb = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_showordernb';
        $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
        if (in_array('DOLUSERCOOKIE_box_' . $this->boxcode, $autosetarray)) {
            $year = GETPOST($param_year, 'int');
            $showinvoicenb = GETPOST($param_showinvoicenb, 'alpha');
            $showpropalnb = GETPOST($param_showpropalnb, 'alpha');
            $showordernb = GETPOST($param_showordernb, 'alpha');
        } else {
            $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_' . $this->boxcode], true);
            $year = $tmparray['year'];
            $showinvoicenb = $tmparray['showinvoicenb'];
            $showpropalnb = $tmparray['showpropalnb'];
            $showordernb = $tmparray['showordernb'];
        }
        if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) {
            $showpropalnb = 1;
            $showinvoicenb = 1;
            $showordernb = 1;
        }
        if (empty($conf->facture->enabled) || empty($user->rights->facture->lire)) {
            $showinvoicenb = 0;
        }
        if (empty($conf->propal->enabled) || empty($user->rights->propal->lire)) {
            $showpropalnb = 0;
        }
        if (empty($conf->commande->enabled) || empty($user->rights->commande->lire)) {
            $showordernb = 0;
        }
        $nowarray = dol_getdate(dol_now(), true);
        if (empty($year)) {
            $year = $nowarray['year'];
        }
        $nbofgraph = 0;
        if ($showinvoicenb) {
            $nbofgraph++;
        }
        if ($showpropalnb) {
            $nbofgraph++;
        }
        if ($showordernb) {
            $nbofgraph++;
        }
        $paramtitle = $langs->transnoentitiesnoconv("Products") . '/' . $langs->transnoentitiesnoconv("Services");
        if (empty($conf->produit->enabled)) {
            $paramtitle = $langs->transnoentitiesnoconv("Services");
        }
        if (empty($conf->service->enabled)) {
            $paramtitle = $langs->transnoentitiesnoconv("Products");
        }
        $socid = empty($user->societe_id) ? 0 : $user->societe_id;
        $userid = 0;
        // No filter on user creation
        $WIDTH = $nbofgraph >= 2 || !empty($conf->dol_optimize_smallscreen) ? '160' : '320';
        $HEIGHT = '192';
        if (!empty($conf->facture->enabled) && !empty($user->rights->facture->lire)) {
            // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
            if ($showinvoicenb) {
                include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php';
                $showpointvalue = 1;
                $nocolor = 0;
                $mode = 'customer';
                $stats_invoice = new FactureStats($this->db, $socid, $mode, $userid > 0 ? $userid : 0);
                $data1 = $stats_invoice->getAllByProductEntry($year, GETPOST('action') == $refreshaction ? -1 : 3600 * 24);
                if (empty($data1)) {
                    $showpointvalue = 0;
                    $nocolor = 1;
                    $data1 = array(array(0 => $langs->trans("None"), 1 => 1));
                }
                $filenamenb = $dir . "/prodserforinvoice-" . $year . ".png";
                $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=productstats&amp;file=prodserforinvoice-' . $year . '.png';
                $px1 = new DolGraph();
                $mesg = $px1->isGraphKo();
                if (!$mesg) {
                    $i = 0;
                    $tot = count($data1);
                    $legend = array();
                    while ($i <= $tot) {
                        $data1[$i][0] = dol_trunc($data1[$i][0], 5);
                        // Required to avoid error "Could not draw pie with labels contained inside canvas"
                        $legend[] = $data1[$i][0];
                        $i++;
                    }
                    $px1->SetData($data1);
                    unset($data1);
                    if ($nocolor) {
                        $px1->SetDataColor(array(array(220, 220, 220)));
                    }
                    $px1->SetPrecisionY(0);
                    $px1->SetLegend($legend);
                    $px1->setShowLegend(0);
                    $px1->setShowPointValue($showpointvalue);
                    $px1->setShowPercent(0);
                    $px1->SetMaxValue($px1->GetCeilMaxValue());
                    $px1->SetWidth($WIDTH);
                    $px1->SetHeight($HEIGHT);
                    //$px1->SetYLabel($langs->trans("NumberOfBills"));
                    $px1->SetShading(3);
                    $px1->SetHorizTickIncrement(1);
                    $px1->SetPrecisionY(0);
                    $px1->SetCssPrefix("cssboxes");
                    //$px1->mode='depth';
                    $px1->SetType(array('pie'));
                    $px1->SetTitle($langs->trans("BoxProductDistributionFor", $paramtitle, $langs->transnoentitiesnoconv("Invoices")));
                    $px1->draw($filenamenb, $fileurlnb);
                }
            }
        }
        if (!empty($conf->propal->enabled) && !empty($user->rights->propal->lire)) {
            // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
            if ($showpropalnb) {
                include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propalestats.class.php';
                $showpointvalue = 1;
                $nocolor = 0;
                $stats_proposal = new PropaleStats($this->db, $socid, $userid > 0 ? $userid : 0);
                $data2 = $stats_proposal->getAllByProductEntry($year, GETPOST('action') == $refreshaction ? -1 : 3600 * 24);
                if (empty($data2)) {
                    $showpointvalue = 0;
                    $nocolor = 1;
                    $data2 = array(array(0 => $langs->trans("None"), 1 => 1));
                }
                $filenamenb = $dir . "/prodserforpropal-" . $year . ".png";
                $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=proposalstats&amp;file=prodserforpropal-' . $year . '.png';
                $px2 = new DolGraph();
                $mesg = $px2->isGraphKo();
                if (!$mesg) {
                    $i = 0;
                    $tot = count($data2);
                    $legend = array();
                    while ($i <= $tot) {
                        $data2[$i][0] = dol_trunc($data2[$i][0], 5);
                        // Required to avoid error "Could not draw pie with labels contained inside canvas"
                        $legend[] = $data2[$i][0];
                        $i++;
                    }
                    $px2->SetData($data2);
                    unset($data2);
                    if ($nocolor) {
                        $px2->SetDataColor(array(array(220, 220, 220)));
                    }
                    $px2->SetPrecisionY(0);
                    $px2->SetLegend($legend);
                    $px2->setShowLegend(0);
                    $px2->setShowPointValue($showpointvalue);
                    $px2->setShowPercent(0);
                    $px2->SetMaxValue($px2->GetCeilMaxValue());
                    $px2->SetWidth($WIDTH);
                    $px2->SetHeight($HEIGHT);
                    //$px2->SetYLabel($langs->trans("AmountOfBillsHT"));
                    $px2->SetShading(3);
                    $px2->SetHorizTickIncrement(1);
                    $px2->SetPrecisionY(0);
                    $px2->SetCssPrefix("cssboxes");
                    //$px2->mode='depth';
                    $px2->SetType(array('pie'));
                    $px2->SetTitle($langs->trans("BoxProductDistributionFor", $paramtitle, $langs->transnoentitiesnoconv("Proposals")));
                    $px2->draw($filenamenb, $fileurlnb);
                }
            }
        }
        if (!empty($conf->commande->enabled) && !empty($user->rights->commande->lire)) {
            // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
            if ($showordernb) {
                include_once DOL_DOCUMENT_ROOT . '/commande/class/commandestats.class.php';
                $showpointvalue = 1;
                $nocolor = 0;
                $mode = 'customer';
                $stats_order = new CommandeStats($this->db, $socid, $mode, $userid > 0 ? $userid : 0);
                $data3 = $stats_order->getAllByProductEntry($year, GETPOST('action') == $refreshaction ? -1 : 3600 * 24);
                if (empty($data3)) {
                    $showpointvalue = 0;
                    $nocolor = 1;
                    $data3 = array(array(0 => $langs->trans("None"), 1 => 1));
                }
                $filenamenb = $dir . "/prodserfororder-" . $year . ".png";
                $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=orderstats&amp;file=prodserfororder-' . $year . '.png';
                $px3 = new DolGraph();
                $mesg = $px3->isGraphKo();
                if (!$mesg) {
                    $i = 0;
                    $tot = count($data3);
                    $legend = array();
                    while ($i <= $tot) {
                        $data3[$i][0] = dol_trunc($data3[$i][0], 5);
                        // Required to avoid error "Could not draw pie with labels contained inside canvas"
                        $legend[] = $data3[$i][0];
                        $i++;
                    }
                    $px3->SetData($data3);
                    unset($data3);
                    if ($nocolor) {
                        $px3->SetDataColor(array(array(220, 220, 220)));
                    }
                    $px3->SetPrecisionY(0);
                    $px3->SetLegend($legend);
                    $px3->setShowLegend(0);
                    $px3->setShowPointValue($showpointvalue);
                    $px3->setShowPercent(0);
                    $px3->SetMaxValue($px3->GetCeilMaxValue());
                    $px3->SetWidth($WIDTH);
                    $px3->SetHeight($HEIGHT);
                    //$px3->SetYLabel($langs->trans("AmountOfBillsHT"));
                    $px3->SetShading(3);
                    $px3->SetHorizTickIncrement(1);
                    $px3->SetPrecisionY(0);
                    $px3->SetCssPrefix("cssboxes");
                    //$px3->mode='depth';
                    $px3->SetType(array('pie'));
                    $px3->SetTitle($langs->trans("BoxProductDistributionFor", $paramtitle, $langs->transnoentitiesnoconv("Orders")));
                    $px3->draw($filenamenb, $fileurlnb);
                }
            }
        }
        if (empty($conf->use_javascript_ajax)) {
            $langs->load("errors");
            $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
        }
        if (!$mesg) {
            $stringtoshow = '';
            $stringtoshow .= '<script type="text/javascript" language="javascript">
				jQuery(document).ready(function() {
					jQuery("#idsubimg' . $this->boxcode . '").click(function() {
						jQuery("#idfilter' . $this->boxcode . '").toggle();
					});
				});
			</script>';
            $stringtoshow .= '<div class="center hideobject" id="idfilter' . $this->boxcode . '">';
            // hideobject is to start hidden
            $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
            $stringtoshow .= '<input type="hidden" name="action" value="' . $refreshaction . '">';
            $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_' . $this->boxcode . ':year,showinvoicenb,showpropalnb,showordernb">';
            if (!empty($conf->facture->enabled) || !empty($user->rights->facture->lire)) {
                $stringtoshow .= '<input type="checkbox" name="' . $param_showinvoicenb . '"' . ($showinvoicenb ? ' checked="true"' : '') . '> ' . $langs->trans("ForCustomersInvoices");
                $stringtoshow .= ' &nbsp; ';
            }
            if (!empty($conf->propal->enabled) || !empty($user->rights->propal->lire)) {
                $stringtoshow .= '<input type="checkbox" name="' . $param_showpropalnb . '"' . ($showpropalnb ? ' checked="true"' : '') . '> ' . $langs->trans("ForProposals");
                $stringtoshow .= '&nbsp;';
            }
            if (!empty($conf->commande->enabled) || !empty($user->rights->commande->lire)) {
                $stringtoshow .= '<input type="checkbox" name="' . $param_showordernb . '"' . ($showordernb ? ' checked="true"' : '') . '> ' . $langs->trans("ForCustomersOrders");
            }
            $stringtoshow .= '<br>';
            $stringtoshow .= $langs->trans("Year") . ' <input class="flat" size="4" type="text" name="' . $param_year . '" value="' . $year . '">';
            $stringtoshow .= '<input type="image" alt="' . $langs->trans("Refresh") . '" src="' . img_picto('', 'refresh.png', '', '', 1) . '">';
            $stringtoshow .= '</form>';
            $stringtoshow .= '</div>';
            if ($nbofgraph == 1) {
                if ($showinvoicenb) {
                    $stringtoshow .= $px1->show();
                } else {
                    if ($showpropalnb) {
                        $stringtoshow .= $px2->show();
                    } else {
                        $stringtoshow .= $px3->show();
                    }
                }
            }
            if ($nbofgraph == 2) {
                $stringtoshow .= '<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
                if ($showinvoicenb) {
                    $stringtoshow .= $px1->show();
                } else {
                    if ($showpropalnb) {
                        $stringtoshow .= $px2->show();
                    }
                }
                $stringtoshow .= '</div><div class="fichehalfright">';
                if ($showordernb) {
                    $stringtoshow .= $px3->show();
                } else {
                    if ($showpropalnb) {
                        $stringtoshow .= $px2->show();
                    }
                }
                $stringtoshow .= '</div></div></div>';
            }
            if ($nbofgraph == 3) {
                $stringtoshow .= '<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
                $stringtoshow .= $px1->show();
                $stringtoshow .= '</div><div class="fichehalfright">';
                $stringtoshow .= $px2->show();
                $stringtoshow .= '</div></div></div>';
                $stringtoshow .= '<div class="fichecenter"><div class="containercenter">';
                $stringtoshow .= $px3->show();
                $stringtoshow .= '</div></div>';
            }
            $this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"', 'textnoformat' => $stringtoshow);
        } else {
            $this->info_box_contents[0][0] = array('td' => 'align="left" class="nohover"', 'maxlength' => 500, 'text' => $mesg);
        }
    }
Esempio n. 15
0
    echo " </tr>\n";

    echo "</table>\n";
}
else    // View by day
{
    $newparam=$param;   // newparam is for birthday links
    $newparam=preg_replace('/action=show_month&?/i','',$newparam);
    $newparam=preg_replace('/action=show_week&?/i','',$newparam);
    $newparam=preg_replace('/day=[0-9][0-9]&?/i','',$newparam);
    $newparam=preg_replace('/month=[0-9][0-9]&?/i','',$newparam);
    $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
    // Code to show just one day
    $style='cal_current_month';
    $today=0;
    $todayarray=dol_getdate($now,'fast');
    if ($todayarray['mday']==$day && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
    if ($today) $style='cal_today';

    $timestamp=dol_mktime(12,0,0,$month,$day,$year);
    $arraytimestamp=adodb_getdate(dol_mktime(12,0,0,$month,$day,$year));
    echo '<table width="100%" class="nocellnopadd">';
    echo ' <tr class="liste_titre">';
    echo '  <td align="center">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
    $maxnbofchar=80;
    show_day_events ($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
    echo "</td>\n";
    echo " </tr>\n";
Esempio n. 16
0
$mine = $_REQUEST['mode'] == 'mine' ? 1 : 0;
// Security check
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
//$result = restrictedArea($user, 'projet', $projectid);
if (!$user->rights->projet->lire) {
    accessforbidden();
}
$langs->load("projects");
/*
 * View
 */
$now = dol_now();
$tmp = dol_getdate($now);
$day = $tmp['mday'];
$month = $tmp['mon'];
$year = $tmp['year'];
$projectstatic = new Project($db);
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
// Return all projects I have permission on because I want my tasks and some of my task may be on a public projet that is not my project
$taskstatic = new Task($db);
$tasktmp = new Task($db);
$title = $langs->trans("Activities");
if ($mine) {
    $title = $langs->trans("MyActivities");
}
llxHeader("", $title);
print load_fiche_titre($title, '', 'title_project');
if ($mine) {
Esempio n. 17
0
    $newparam = $param;
    // newparam is for birthday links
    $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
    $newparam = preg_replace('/action=show_week&?/i', '', $newparam);
    $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
    $newparam .= '&viewday=1';
    // Code to show just one day
    $style = 'cal_current_month cal_current_month_oneday';
    $today = 0;
    $todayarray = dol_getdate($now, 'fast');
    if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
        $today = 1;
    }
    //if ($today) $style='cal_today';
    $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
    $arraytimestamp = dol_getdate($timestamp);
    echo '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
    echo ' <tr class="liste_titre">';
    echo '  <td align="center">' . $langs->trans("Day" . $arraytimestamp['wday']) . "</td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo '  <td class="' . $style . '" width="14%" valign="top">';
    $maxnbofchar = 80;
    show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
    echo "</td>\n";
    echo " </tr>\n";
    echo '</table>';
}
/* TODO Export
 print '
<a href="" id="actionagenda_ical_link"><img src="'.DOL_URL_ROOT.'/theme/common/ical.gif" border="0"/></a>
Esempio n. 18
0
            print '<input type="hidden" name="fichinterid" value="'.$object->id.'">';
            print '<input type="hidden" name="action" value="addline">';

            $var=false;

            print '<tr '.$bc[$var].">\n";
            print '<td>';
            // editeur wysiwyg
            require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
            $doleditor=new DolEditor('np_desc',$_POST["np_desc"],'',100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
            $doleditor->Create();
            print '</td>';

            // Date intervention
            print '<td align="center" nowrap="nowrap">';
            $timearray=dol_getdate(mktime());
            $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']);
            $html->select_date($timewithnohour,'di',1,1,0,"addinter");
            print '</td>';

            // Duration
            print '<td align="right">';
            $html->select_duration('duration',3600);
            print '</td>';

            print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
            print '</tr>';

            print '</form>';

            if (! $num) print '</table>';
Esempio n. 19
0
$projectid = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$datesrfc = GETPOST('datesrfc');
$dateerfc = GETPOST('dateerfc');
$dates = dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
$datee = dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
if (empty($dates) && !empty($datesrfc)) {
    $dates = dol_stringtotime($datesrfc);
}
if (empty($datee) && !empty($dateerfc)) {
    $datee = dol_stringtotime($dateerfc);
}
if (!isset($_POST['datesrfc']) && !isset($_POST['datesday']) && !empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR)) {
    $new = dol_now();
    $tmp = dol_getdate($new);
    //$datee=$now
    //$dates=dol_time_plus_duree($datee, -1, 'y');
    $dates = dol_get_first_day($tmp['year'], 1);
}
if ($projectid == '' && $ref == '') {
    dol_print_error('', 'Bad parameter');
    exit;
}
$mine = $_REQUEST['mode'] == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
$project = new Project($db);
if ($id > 0 || !empty($ref)) {
    $project->fetch($id, $ref);
    $project->fetch_thirdparty();
    $projectid = $project->id;
Esempio n. 20
0
 */
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT . '/holiday/common.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
// Protection if external user
if ($user->societe_id > 0) {
    accessforbidden();
}
// Si l'utilisateur n'a pas le droit de lire cette page
if (!$user->rights->holiday->read_all) {
    accessforbidden();
}
$year = GETPOST('year');
if (empty($year)) {
    $tmpdate = dol_getdate(dol_now());
    $year = $tmpdate['year'];
}
$langs->load('users');
/*
 * View
 */
$cp = new Holiday($db);
llxHeader(array(), $langs->trans('CPTitreMenu') . ' (' . $langs->trans("Year") . ' ' . $year . ')');
// Recent changes are more important than old changes
$log_holiday = $cp->fetchLog('ORDER BY cpl.rowid DESC', " AND date_action BETWEEN '" . $db->idate(dol_get_first_day($year, 1, 1)) . "' AND '" . $db->idate(dol_get_last_day($year, 12, 1)) . "'");
// Load $cp->logs
print load_fiche_titre($langs->trans('LogCP'), '<div class="pagination"><ul><li class="pagination"><a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year - 1) . '">&lt;</a><li class="pagination"><a href="">' . $langs->trans("Year") . ' ' . $year . '</a></li><li class="pagination"><a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year + 1) . '">&gt;</a></li></lu></div>', 'title_hrm.png');
print '<div class="info">' . $langs->trans('LastUpdateCP') . ': ' . "\n";
if ($cp->getConfCP('lastUpdate')) {
    print '<strong>' . dol_print_date($db->jdate($cp->getConfCP('lastUpdate')), 'dayhour', 'tzuser') . '</strong>';
Esempio n. 21
0
/**
 * 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 = '&nbsp;';
        $string2 = '&nbsp;';
        $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 = '&nbsp;';
            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 = '&nbsp;';
            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>';
    }
}
/**
 * Show box
 *
 * @param	string	$selectedDate	Date YYYMMDD
 * @param	int		$month			Month
 * @param 	int		$year			Year
 * @return	void
 */
function displayBox($selectedDate, $month, $year)
{
    global $langs, $conf;
    //print "$selectedDate,$month,$year";
    $thedate = dol_mktime(12, 0, 0, $month, 1, $year);
    //print "thedate=$thedate";
    $today = dol_now();
    $todayArray = dol_getdate($today);
    if ($selectedDate != "00000000") {
        $selDate = xyzToUnixTimestamp($selectedDate);
        $xyz = dol_print_date($selDate, "%Y%m%d");
    } else {
        $selDate = 0;
        $xyz = 0;
    }
    ?>
<table class="dp">
	<tr>
		<td colspan="6" class="dpHead"><?php 
    $selectMonth = dol_print_date($thedate, '%m');
    $selectYear = dol_print_date($thedate, '%Y');
    echo $langs->trans("Month" . $selectMonth) . ", " . $selectYear;
    ?>
</td>
		<td class="dpHead">
		<button type="button" class="dpInvisibleButtons" id="DPCancel"
			onClick="closeDPBox();">X</button>
		</td>
	</tr>
	<tr>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo $month;
    ?>
','<?php 
    echo $year - 1;
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&lt;&lt;</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    if ($month == 1) {
        echo "12";
    } else {
        echo $month - 1;
    }
    ?>
','<?php 
    if ($month == 1) {
        echo $year - 1;
    } else {
        echo $year;
    }
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&lt;</td>
		<td colspan="3" class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo (int) dol_print_date($today, '%m');
    ?>
','<?php 
    echo $todayArray["year"];
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')"><?php 
    echo '-';
    ?>
</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    if ($month == 12) {
        echo "1";
    } else {
        echo $month + 1;
    }
    ?>
','<?php 
    if ($month == 12) {
        echo $year + 1;
    } else {
        echo $year;
    }
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&gt;</td>
		<td class="dpButtons"
			onClick="loadMonth('<?php 
    echo DOL_URL_ROOT . '/core/';
    ?>
','<?php 
    echo $month;
    ?>
','<?php 
    echo $year + 1;
    ?>
','<?php 
    echo $xyz;
    ?>
','<?php 
    echo $langs->defaultlang;
    ?>
')">&gt;&gt;</td>
	</tr>
	<tr class="dpDayNames">
		<td width="14%"><?php 
    echo $langs->trans("ShortSunday");
    ?>
</td>
		<td width="14%"><?php 
    echo $langs->trans("ShortMonday");
    ?>
</td>
		<td width="15%"><?php 
    echo $langs->trans("ShortTuesday");
    ?>
</td>
		<td width="14%"><?php 
    echo $langs->trans("ShortWednesday");
    ?>
</td>
		<td width="15%"><?php 
    echo $langs->trans("ShortThursday");
    ?>
</td>
		<td width="14%"><?php 
    echo $langs->trans("ShortFriday");
    ?>
</td>
		<td width="14%"><?php 
    echo $langs->trans("ShortSaturday");
    ?>
</td>
	</tr>
	<?php 
    //print "x ".$thedate." y";
    $firstdate = dol_getdate($thedate);
    $mydate = $firstdate;
    // Loop on each day of month
    $stoploop = 0;
    $day = 1;
    $cols = 0;
    while (!$stoploop) {
        //print_r($mydate);
        if ($firstdate == $mydate) {
            echo "<TR class=\"dpWeek\">";
            $cols = 0;
            for ($i = 0; $i < $mydate["wday"]; $i++) {
                echo "<TD>&nbsp;</TD>";
                $cols++;
            }
        } else {
            if ($mydate["wday"] == 0) {
                echo "<TR class=\"dpWeek\">";
                $cols = 0;
            }
        }
        $dayclass = "dpReg";
        if ($thedate == $selDate) {
            $dayclass = "dpSelected";
        } elseif ($thedate == $today) {
            $dayclass = "dpToday";
        }
        if ($langs->trans("FormatDateShortJavaInput") == "FormatDateShortJavaInput") {
            print "ERROR FormatDateShortJavaInput not defined for language " . $langs->defaultlang;
            exit;
        }
        // Sur click dans calendrier, appelle fonction dpClickDay
        echo "<TD class=\"" . $dayclass . "\"";
        echo " onMouseOver=\"dpHighlightDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",tradMonths)\"";
        echo " onClick=\"dpClickDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",'" . $langs->trans("FormatDateShortJavaInput") . "')\"";
        echo ">" . sprintf("%02s", $mydate["mday"]) . "</TD>";
        $cols++;
        if ($mydate["wday"] == 6) {
            echo "</TR>\n";
        }
        //$thedate=strtotime("tomorrow",$thedate);
        $day++;
        $thedate = dol_mktime(12, 0, 0, $month, $day, $year);
        if ($thedate == '') {
            $stoploop = 1;
        } else {
            $mydate = dol_getdate($thedate);
            if ($firstdate["month"] != $mydate["month"]) {
                $stoploop = 1;
            }
        }
    }
    if ($cols < 7) {
        for ($i = 6; $i >= $cols; $i--) {
            echo "<TD>&nbsp;</TD>";
        }
        echo "</TR>\n";
    }
    ?>
	<tr>
		<td id="dpExp" class="dpExplanation" colspan="7"><?php 
    if ($selDate) {
        $tempDate = dol_getdate($selDate);
        print $langs->trans("Month" . $selectMonth) . " ";
        print sprintf("%02s", $tempDate["mday"]);
        print ", " . $selectYear;
    } else {
        print "Click a Date";
    }
    ?>
</td>
	</tr>
</table>
		<?php 
}
Esempio n. 23
0
/**	Return first day of week for a date
 *
 *	@param		int		$day		Day
 * 	@param		int		$month		Month
 *  @param		int		$year		Year
 * 	@param		int		$gm			False = Return date to compare with server TZ, True to compare with GM date.
 *	@return		array				year,month, week,first_day,prev_year,prev_month,prev_day
 */
function dol_get_first_day_week($day, $month, $year, $gm = false)
{
    global $conf;
    $date = dol_mktime(0, 0, 0, $month, $day, $year, $gm);
    //Checking conf of start week
    $start_week = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1;
    $tmparray = dol_getdate($date, true);
    //Calculate days to count
    $days = $start_week - $tmparray['wday'];
    if ($days >= 1) {
        $days = 7 - $days;
    }
    $days = abs($days);
    $seconds = $days * 24 * 60 * 60;
    //Get first day of week
    $tmpday = date($tmparray[0]) - $seconds;
    $tmpday = date("d", $tmpday);
    //Check first day of week is form this month or not
    if ($tmpday > $day) {
        $prev_month = $month - 1;
        $prev_year = $year;
        if ($prev_month == 0) {
            $prev_month = 12;
            $prev_year = $year - 1;
        }
    } else {
        $prev_month = $month;
        $prev_year = $year;
    }
    //Get first day of next week
    $tmptime = dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
    $tmptime -= 24 * 60 * 60 * 7;
    $tmparray = dol_getdate($tmptime, true);
    $prev_day = $tmparray['mday'];
    //Check first day of week is form this month or not
    if ($prev_day > $tmpday) {
        $prev_month = $month - 1;
        $prev_year = $year;
        if ($prev_month == 0) {
            $prev_month = 12;
            $prev_year = $year - 1;
        }
    }
    $week = date("W", dol_mktime(0, 0, 0, $month, $tmpday, $year, $gm));
    return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day);
}
Esempio n. 24
0
 /**
  * testDolGetDate
  *
  * @return boolean
  */
 public function testDolGetDate()
 {
     global $conf;
     $conf->global->MAIN_START_WEEK = 0;
     $tmp = dol_getdate(1);
     // 1/1/1970 and 1 second = thirday
     $this->assertEquals(4, $tmp['wday']);
     $tmp = dol_getdate(24 * 60 * 60 + 1);
     // 2/1/1970 and 1 second = friday
     $this->assertEquals(5, $tmp['wday']);
     $conf->global->MAIN_START_WEEK = 1;
     $tmp = dol_getdate(1);
     // 1/1/1970 and 1 second = thirday
     $this->assertEquals(4, $tmp['wday']);
     $tmp = dol_getdate(24 * 60 * 60 + 1);
     // 2/1/1970 and 1 second = friday
     $this->assertEquals(5, $tmp['wday']);
     return true;
 }