Ejemplo n.º 1
0
/**
 *	Show informations on an object
 *  TODO Move this into html.formother
 *
 *	@param	Object	$object			Objet to show
 *	@return	void
 */
function dol_print_object_info($object)
{
    global $langs, $db;
    $langs->load("other");
    $langs->load("admin");
    include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
    $deltadateforserver = getServerTimeZoneInt('now');
    $deltadateforclient = (int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst'];
    //$deltadateforcompany=((int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst']);
    $deltadateforuser = round($deltadateforclient - $deltadateforserver);
    //print "x".$deltadateforserver." - ".$deltadateforclient." - ".$deltadateforuser;
    // Import key
    if (isset($object->import_key)) {
        print $langs->trans("ImportedWithSet") . " : " . $object->import_key . '<br>';
    }
    // User creation
    if (isset($object->user_creation)) {
        print $langs->trans("CreatedBy") . " : ";
        if (is_object($object->user_creation)) {
            print $object->user_creation->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_creation);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date creation
    if (isset($object->date_creation)) {
        print $langs->trans("DateCreation") . " : " . dol_print_date($object->date_creation, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_creation + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // User change
    if (isset($object->user_modification)) {
        print $langs->trans("ModifiedBy") . " : ";
        if (is_object($object->user_modification)) {
            print $object->user_modification->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_modification);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date change
    if (isset($object->date_modification)) {
        print $langs->trans("DateLastModification") . " : " . dol_print_date($object->date_modification, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_modification + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // User validation
    if (isset($object->user_validation)) {
        print $langs->trans("ValidatedBy") . " : ";
        if (is_object($object->user_validation)) {
            print $object->user_validation->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_validation);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date validation
    if (isset($object->date_validation)) {
        print $langs->trans("DateValidation") . " : " . dol_print_date($object->date_validation, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_validation + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // User approve
    if (isset($object->user_approve)) {
        print $langs->trans("ApprovedBy") . " : ";
        if (is_object($object->user_approve)) {
            print $object->user_approve->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_approve);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date approve
    if (isset($object->date_approve)) {
        print $langs->trans("DateApprove") . " : " . dol_print_date($object->date_approve, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_approve + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // User close
    if (isset($object->user_cloture)) {
        print $langs->trans("ClosedBy") . " : ";
        if (is_object($object->user_cloture)) {
            print $object->user_cloture->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_cloture);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date close
    if (isset($object->date_cloture)) {
        print $langs->trans("DateClosing") . " : " . dol_print_date($object->date_cloture, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_cloture + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // User conciliate
    if (isset($object->user_rappro)) {
        print $langs->trans("ConciliatedBy") . " : ";
        if (is_object($object->user_rappro)) {
            print $object->user_rappro->getNomUrl(1);
        } else {
            $userstatic = new User($db);
            $userstatic->fetch($object->user_rappro);
            print $userstatic->getNomUrl(1);
        }
        print '<br>';
    }
    // Date conciliate
    if (isset($object->date_rappro)) {
        print $langs->trans("DateConciliating") . " : " . dol_print_date($object->date_rappro, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_rappro + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
    // Date send
    if (isset($object->date_envoi)) {
        print $langs->trans("DateLastSend") . " : " . dol_print_date($object->date_envoi, "dayhour");
        if ($deltadateforuser) {
            print ' ' . $langs->trans("CurrentHour") . ' &nbsp; / &nbsp; ' . dol_print_date($object->date_envoi + $deltadateforuser * 3600, "dayhour") . ' &nbsp;' . $langs->trans("ClientHour");
        }
        print '<br>';
    }
}
    print "</tr>\n";
}
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => price(1234.56)</td><td>' . price(1234.56) . '</td></tr>' . "\n";
// Timezone
$txt = $langs->trans("OSTZ") . ' (variable system TZ): ' . (!empty($_ENV["TZ"]) ? $_ENV["TZ"] : $langs->trans("NotDefined")) . '<br>' . "\n";
$txt .= $langs->trans("PHPTZ") . ' (php.ini date.timezone): ' . (ini_get("date.timezone") ? ini_get("date.timezone") : $langs->trans("NotDefined")) . '' . "<br>\n";
// date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php
$txt .= $langs->trans("Dolibarr constant MAIN_SERVER_TZ") . ': ' . (empty($conf->global->MAIN_SERVER_TZ) ? $langs->trans("NotDefined") : $conf->global->MAIN_SERVER_TZ);
//$txt.=$langs->trans("YouCanEditPHPTZ"); // deprecated
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">' . $langs->trans("CurrentTimeZone") . '</td><td>';
// Timezone server PHP
$a = getServerTimeZoneInt('now');
$b = getServerTimeZoneInt('winter');
$c = getServerTimeZoneInt('summer');
$daylight = is_numeric($c) && is_numeric($b) ? round($c - $b) : 'unknown';
//print $a." ".$b." ".$c." ".$daylight;
$val = ($a >= 0 ? '+' : '') . $a;
$val .= ' (' . ($a === 'unknown' ? 'unknown' : ($a >= 0 ? '+' : '') . $a * 3600) . ')';
$val .= ' &nbsp; &nbsp; &nbsp; ' . getServerTimeZoneString();
$val .= ' &nbsp; &nbsp; &nbsp; ' . $langs->trans("DaylingSavingTime") . ': ' . ($daylight === 'unknown' ? 'unknown' : ($a == $c ? yn($daylight) : yn(0) . ($daylight ? '  &nbsp; &nbsp; (' . $langs->trans('YesInSummer') . ')' : '')));
print $form->textwithtooltip($val, $txt, 2, 1, img_info(''));
print '</td></tr>' . "\n";
// value defined in http://fr3.php.net/manual/en/timezones.europe.php
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => ' . $langs->trans("CurrentHour") . '</td><td>' . dol_print_date(dol_now(), 'dayhour', 'tzserver') . '</td></tr>' . "\n";
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => dol_print_date(0,"dayhourtext")</td><td>' . dol_print_date(0, "dayhourtext") . '</td>';
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => dol_get_first_day(1970,1,false)</td><td>' . dol_get_first_day(1970, 1, false) . ' &nbsp; &nbsp; (=> dol_print_date() or idate() of this value = ' . dol_print_date(dol_get_first_day(1970, 1, false), 'dayhour') . ')</td>';
Ejemplo n.º 3
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			$addnowbutton	Add a button "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
  * 	@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, $addnowbutton = 0, $nooutput = 0, $disabled = 0, $fullday = '')
 {
     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="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 {
             // Day
             $retstring .= '<select' . ($disabled ? ' disabled="disabled"' : '') . ' class="flat" name="' . $prefix . 'day">';
             if ($emptydate || $set_time == -1) {
                 $retstring .= '<option value="0" selected="selected">&nbsp;</option>';
             }
             for ($day = 1; $day <= 31; $day++) {
                 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected="selected"' : '') . '>' . $day . '</option>';
             }
             $retstring .= "</select>";
             $retstring .= '<select' . ($disabled ? ' disabled="disabled"' : '') . ' class="flat" name="' . $prefix . 'month">';
             if ($emptydate || $set_time == -1) {
                 $retstring .= '<option value="0" selected="selected">&nbsp;</option>';
             }
             // Month
             for ($month = 1; $month <= 12; $month++) {
                 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected="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="disabled"' : '') . ' placeholder="' . dol_escape_htmltag($langs->trans("Year")) . '" class="flat" type="text" size="3" maxlength="4" name="' . $prefix . 'year" value="' . $syear . '">';
             } else {
                 $retstring .= '<select' . ($disabled ? ' disabled="disabled"' : '') . ' class="flat" name="' . $prefix . 'year">';
                 for ($year = $syear - 5; $year < $syear + 10; $year++) {
                     $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected="true"' : '') . '>' . $year . '</option>';
                 }
                 $retstring .= "</select>\n";
             }
         }
     }
     if ($d && $h) {
         $retstring .= '&nbsp;';
     }
     if ($h) {
         // Show hour
         $retstring .= '<select' . ($disabled ? ' disabled="disabled"' : '') . ' class="flat ' . ($fullday ? $fullday . '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="true"' : '') . '>' . $hour . (empty($conf->dol_optimize_smallscreen) ? '' : 'H') . '</option>';
         }
         $retstring .= '</select>';
         if (empty($conf->dol_optimize_smallscreen)) {
             $retstring .= ":";
         }
     }
     if ($m) {
         // Show minutes
         $retstring .= '<select' . ($disabled ? ' disabled="disabled"' : '') . ' class="flat ' . ($fullday ? $fullday . '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="true"' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>';
         }
         $retstring .= '</select>';
     }
     // Add a "Now" button
     if ($conf->use_javascript_ajax && $addnowbutton) {
         // Script which will be inserted in the OnClick of the "Now" button
         $reset_scripts = "";
         // Generate the date part, depending on the use or not of the javascript calendar
         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\'); ';
         }
         // Generate 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\'); ';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // Generate 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\'); ';
             if ($fullday) {
                 $reset_scripts .= ' } ';
             }
         }
         // If reset_scripts is not empty, print the button with the reset_scripts in 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> ';
         }
     }
     if (!empty($nooutput)) {
         return $retstring;
     }
     print $retstring;
     return;
 }
Ejemplo n.º 4
0
 /**
  * testDolNow
  *
  * @return	void
  */
 public function testDolNow()
 {
     $now=dol_now('gmt');
     $nowtzserver=dol_now('tzserver');
     print __METHOD__."getServerTimeZoneInt=".(getServerTimeZoneInt('now')*3600)."\n";
     $this->assertEquals(getServerTimeZoneInt('now')*3600,($nowtzserver-$now));
 }
Ejemplo n.º 5
0
/**
 *	Return date for now. In mot cases, we use this function without parameters (that means GMT time).
 *
 * 	@param	string		$mode	'gmt' => we return GMT timestamp,
 * 								'tzserver' => we add the PHP server timezone
 *  							'tzref' => we add the company timezone
 * 								'tzuser' => we add the user timezone
 *	@return int   $date	Timestamp
 */
function dol_now($mode = 'gmt')
{
    // Note that gmmktime and mktime return same value (GMT) when used without parameters
    //if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
    if ($mode == 'gmt') {
        $ret = time();
    } else {
        if ($mode == 'tzserver') {
            require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
            $tzsecond = getServerTimeZoneInt('now');
            // Contains tz+dayling saving time
            $ret = dol_now('gmt') + $tzsecond * 3600;
        } else {
            if ($mode == 'tzuser') {
                //print 'eeee'.time().'-'.mktime().'-'.gmmktime();
                $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
                $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60;
                $ret = dol_now('gmt') + ($offsettz + $offsetdst);
            }
        }
    }
    return $ret;
}