Merge pull request #25801 from Hystepik/bookcal_dev_2
New : Bookcal dev 2
This commit is contained in:
commit
325eecdb7f
8 changed files with 187 additions and 47 deletions
|
|
@ -102,7 +102,7 @@ class Availabilities extends CommonObject
|
|||
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields=array(
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>2, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
|
||||
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>"Help text", 'showoncombobox'=>'2', 'validate'=>'1',),
|
||||
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3, 'validate'=>'1',),
|
||||
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
|
||||
|
|
|
|||
|
|
@ -300,6 +300,11 @@ class ActionComm extends CommonObject
|
|||
*/
|
||||
public $elementtype;
|
||||
|
||||
/**
|
||||
* @var int id of availability
|
||||
*/
|
||||
public $fk_bookcal_availability;
|
||||
|
||||
/**
|
||||
* @var string Ical name
|
||||
*/
|
||||
|
|
@ -539,6 +544,7 @@ class ActionComm extends CommonObject
|
|||
$sql .= "transparency,";
|
||||
$sql .= "fk_element,";
|
||||
$sql .= "elementtype,";
|
||||
$sql .= "fk_bookcal_availability,";
|
||||
$sql .= "entity,";
|
||||
$sql .= "extraparams,";
|
||||
// Fields emails
|
||||
|
|
@ -581,6 +587,7 @@ class ActionComm extends CommonObject
|
|||
$sql .= "'".$this->db->escape($this->transparency)."', ";
|
||||
$sql .= (!empty($this->fk_element) ? ((int) $this->fk_element) : "null").", ";
|
||||
$sql .= (!empty($this->elementtype) ? "'".$this->db->escape($this->elementtype)."'" : "null").", ";
|
||||
$sql .= (!empty($this->fk_bookcal_availability) ? "'".$this->db->escape($this->fk_bookcal_availability)."'" : "null").", ";
|
||||
$sql .= ((int) $conf->entity).",";
|
||||
$sql .= (!empty($this->extraparams) ? "'".$this->db->escape($this->extraparams)."'" : "null").", ";
|
||||
// Fields emails
|
||||
|
|
|
|||
|
|
@ -557,6 +557,34 @@ if ($user->rights->agenda->myactions->create || $user->hasRight('agenda', 'allac
|
|||
$s = ''; $link = '';
|
||||
|
||||
$showextcals = $listofextcals;
|
||||
$bookcalcalendars = array();
|
||||
|
||||
// Load Bookcal Calendars
|
||||
if (isModEnabled("bookcal")) {
|
||||
$sql = "SELECT ba.rowid, bc.label, bc.ref, bc.rowid as id_cal";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."bookcal_availabilities as ba";
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."bookcal_calendar as bc";
|
||||
$sql .= " ON bc.rowid = ba.fk_bookcal_calendar";
|
||||
$sql .= " WHERE bc.status = 1";
|
||||
$sql .= " AND ba.status = 1";
|
||||
if (!empty($filtert) && $filtert != -1) {
|
||||
$sql .= " AND bc.visibility = ".(int) $filtert ;
|
||||
}
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$objp = $db->fetch_object($resql);
|
||||
$label = !empty($objp->label) ? $objp->label : $objp->ref;
|
||||
$bookcalcalendars["calendars"][] = array("id" => $objp->id_cal, "label" => $label);
|
||||
$bookcalcalendars["availabilitieslink"][$objp->rowid] = $objp->id_cal;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($conf->use_javascript_ajax)) { // If javascript on
|
||||
$s .= "\n".'<!-- Div to calendars selectors -->'."\n";
|
||||
|
|
@ -564,6 +592,11 @@ if (!empty($conf->use_javascript_ajax)) { // If javascript on
|
|||
$s .= 'jQuery(document).ready(function () {'."\n";
|
||||
$s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });'."\n";
|
||||
$s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });'."\n";
|
||||
if (isModEnabled("bookcal")) {
|
||||
foreach ($bookcalcalendars["calendars"] as $key => $value) {
|
||||
$s .= 'jQuery(".check_bookcal_calendar_'.$value['id'].'").click(function() { console.log("Toggle Bookcal Calendar '.$value['id'].'"); jQuery(".family_bookcal_calendar_'.$value['id'].'").toggle(); });'."\n";
|
||||
}
|
||||
}
|
||||
if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
|
||||
// Code to enable drag and drop
|
||||
$s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
|
||||
|
|
@ -631,6 +664,14 @@ if (!empty($conf->use_javascript_ajax)) { // If javascript on
|
|||
// Birthdays
|
||||
$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> </div>';
|
||||
|
||||
// Bookcal Calendar
|
||||
if (isModEnabled("bookcal")) {
|
||||
foreach ($bookcalcalendars["calendars"] as $key => $value) {
|
||||
$label = $value['label'];
|
||||
$s .= '<div class="nowrap inline-block minheight30"><input '.(GETPOST('check_bookcal_calendar_'.$value['id']) ? "checked" : "").' type="checkbox" id="check_bookcal_calendar_'.$value['id'].'" name="check_bookcal_calendar_'.$value['id'].'" class="check_bookcal_calendar_'.$value['id'].'"><label for="check_bookcal_calendar_'.$value['id'].'"> <span class="check_bookcal_calendar_'.$value['id'].'_text">'.$langs->trans("AgendaShowBookcalCalendar", $label).'</span></label> </div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Calendars from hooks
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
|
||||
|
|
@ -673,7 +714,7 @@ $sql .= ' a.datep2,';
|
|||
$sql .= ' a.percent,';
|
||||
$sql .= ' a.fk_user_author,a.fk_user_action,';
|
||||
$sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
|
||||
$sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
|
||||
$sql .= ' a.fk_soc, a.fk_contact, a.fk_project, a.fk_bookcal_availability,';
|
||||
$sql .= ' a.fk_element, a.elementtype,';
|
||||
$sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
|
||||
|
|
@ -862,6 +903,10 @@ if ($resql) {
|
|||
|
||||
$event->socid = $obj->fk_soc;
|
||||
$event->contact_id = $obj->fk_contact;
|
||||
$event->fk_bookcal_availability = $obj->fk_bookcal_availability;
|
||||
if (!empty($event->fk_bookcal_availability)) {
|
||||
$event->type = "bookcal_calendar";
|
||||
}
|
||||
|
||||
// Defined date_start_in_calendar and date_end_in_calendar property
|
||||
// They are date start and end of action but modified to not be outside calendar view.
|
||||
|
|
@ -1505,7 +1550,7 @@ if (empty($mode) || $mode == 'show_month') { // View by month
|
|||
}
|
||||
//var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
|
||||
echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
|
||||
show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
|
||||
show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam, 0, 60, 0, $bookcalcalendars);
|
||||
echo "</td>\n";
|
||||
} else {
|
||||
/* Show days after the current month (next month) */
|
||||
|
|
@ -1578,7 +1623,7 @@ if (empty($mode) || $mode == 'show_month') { // View by month
|
|||
}
|
||||
|
||||
echo ' <td class="'.$style.'" width="14%" valign="top">';
|
||||
show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
|
||||
show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
|
||||
echo " </td>\n";
|
||||
}
|
||||
echo " </tr>\n";
|
||||
|
|
@ -1668,13 +1713,13 @@ if (empty($mode) || $mode == 'show_month') { // View by month
|
|||
|
||||
echo '</div></div>';
|
||||
|
||||
show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
|
||||
show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1, $bookcalcalendars);
|
||||
|
||||
print '</div>';
|
||||
} else {
|
||||
print '<div class="div-table-responsive-no-min borderbottom">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
||||
|
||||
show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
|
||||
show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
|
||||
|
||||
print '</div>';
|
||||
}
|
||||
|
|
@ -1703,9 +1748,10 @@ $db->close();
|
|||
* @param int $showinfo Add extended information (used by day and week view)
|
||||
* @param int $minheight Minimum height for each event. 60px by default.
|
||||
* @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
|
||||
* @param string $bookcalcalendarsarray Used for Bookcal module array of calendar of bookcal
|
||||
* @return void
|
||||
*/
|
||||
function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
|
||||
function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0, $bookcalcalendarsarray = array())
|
||||
{
|
||||
global $user, $conf, $langs;
|
||||
global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
|
||||
|
|
@ -1817,6 +1863,11 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
|
|||
$colorindex = 2;
|
||||
$cssclass = 'family_birthday ';
|
||||
$color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
|
||||
} elseif ($event->type == 'bookcal_calendar') {
|
||||
$numbirthday++;
|
||||
$colorindex = 3;
|
||||
$cssclass = 'family_bookcal_calendar_'.(!empty($bookcalcalendarsarray[$fk_bookcal_availability]) ? $bookcalcalendarsarray[$fk_bookcal_availability][$event->fk_bookcal_availability] : "");
|
||||
$color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
|
||||
} else {
|
||||
$numother++;
|
||||
$color = ($event->icalcolor ? $event->icalcolor : -1);
|
||||
|
|
@ -1904,6 +1955,9 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
|
|||
if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
|
||||
$morecss = 'hidden';
|
||||
}
|
||||
if ($event->type == 'bookcal_calendar' && !GETPOST('check_bookcal_calendar_'.$bookcalcalendarsarray["availabilitieslink"][$event->fk_bookcal_availability])) {
|
||||
$morecss = 'hidden';
|
||||
}
|
||||
if ($morecss != 'hidden') {
|
||||
$itoshow++;
|
||||
}
|
||||
|
|
@ -1911,8 +1965,11 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
|
|||
$ireallyshown++;
|
||||
}
|
||||
//var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
|
||||
|
||||
print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
|
||||
if (isModEnabled("bookcal") && $event->type == 'bookcal_calendar') {
|
||||
print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.'_'.$bookcalcalendarsarray["availabilitieslink"][$event->fk_bookcal_availability].' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
|
||||
} else {
|
||||
print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
|
||||
}
|
||||
//print ' style="height: 100px;';
|
||||
//print ' position: absolute; top: 40px; width: 50%;';
|
||||
//print '"';
|
||||
|
|
|
|||
|
|
@ -80,11 +80,11 @@ if ($action == 'verifyavailability') {
|
|||
}
|
||||
if (!$error) {
|
||||
$datetocheckbooking_end = dol_time_plus_duree($datetocheckbooking, 1, 'd');
|
||||
$sql = "SELECT b.start, b.rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."bookcal_booking as b";
|
||||
$sql = "SELECT b.datep, b.id";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as b";
|
||||
$sql .= " WHERE fk_bookcal_availability = ".((int) $idavailability);
|
||||
$sql .= " AND b.start >= '".$db->idate($datetocheckbooking)."'";
|
||||
$sql .= " AND b.start < '".$db->idate($datetocheckbooking_end)."'";
|
||||
$sql .= " AND b.datep >= '".$db->idate($datetocheckbooking)."'";
|
||||
$sql .= " AND b.datep < '".$db->idate($datetocheckbooking_end)."'";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
|
|
@ -94,7 +94,7 @@ if ($action == 'verifyavailability') {
|
|||
$response["content"] = array();
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$dateobject = $obj->start;
|
||||
$dateobject = $obj->datep;
|
||||
$dateobject = explode(" ", $dateobject)[1];
|
||||
$dateobject = explode(":", $dateobject);
|
||||
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ class modBookCal extends DolibarrModules
|
|||
$r = 0;
|
||||
// Add here entries to declare new menus
|
||||
/* BEGIN MODULEBUILDER TOPMENU */
|
||||
$this->menu[$r++] = array(
|
||||
/*$this->menu[$r++] = array(
|
||||
'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'type'=>'top', // This is a Top menu entry
|
||||
'titre'=>'ModuleBookCalName',
|
||||
|
|
@ -311,18 +311,33 @@ class modBookCal extends DolibarrModules
|
|||
'perms'=>'$user->rights->bookcal->availabilities->read', // Use 'perms'=>'$user->rights->bookcal->availabilities->read' if you want your menu with a permission rules
|
||||
'target'=>'',
|
||||
'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
|
||||
);
|
||||
);*/
|
||||
/* END MODULEBUILDER TOPMENU */
|
||||
|
||||
/* BEGIN MODULEBUILDER LEFTMENU CALENDAR */
|
||||
$this->menu[$r++] = array(
|
||||
'fk_menu'=>'fk_mainmenu=agenda',
|
||||
'type'=>'left',
|
||||
'titre'=> 'MenuBookcalIndex',
|
||||
'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em92"'),
|
||||
'mainmenu'=>'agenda',
|
||||
'leftmenu'=> 'bookcal',
|
||||
'url'=> '/bookcal/bookcalindex.php',
|
||||
'langs'=> 'bookcal',
|
||||
'position'=> 1100+$r,
|
||||
'enabled'=> '1',
|
||||
'perms'=> '$user->rights->bookcal->calendar->read',
|
||||
'user'=> 0
|
||||
);
|
||||
|
||||
$this->menu[$r++]=array(
|
||||
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'fk_menu'=>'fk_mainmenu=bookcal',
|
||||
'fk_menu'=>'fk_mainmenu=agenda,fk_leftmenu=bookcal',
|
||||
// This is a Left menu entry
|
||||
'type'=>'left',
|
||||
'titre'=>'List Calendar',
|
||||
'mainmenu'=>'bookcal',
|
||||
'leftmenu'=>'bookcal_calendar',
|
||||
'titre'=>'Calendar',
|
||||
'mainmenu'=>'agenda',
|
||||
'leftmenu'=>'bookcal_calendar_list',
|
||||
'url'=>'/bookcal/calendar_list.php',
|
||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'langs'=>'bookcal',
|
||||
|
|
@ -337,12 +352,12 @@ class modBookCal extends DolibarrModules
|
|||
);
|
||||
$this->menu[$r++]=array(
|
||||
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'fk_menu'=>'fk_mainmenu=bookcal,fk_leftmenu=bookcal_calendar',
|
||||
'fk_menu'=>'fk_mainmenu=agenda,fk_leftmenu=bookcal_calendar_list',
|
||||
// This is a Left menu entry
|
||||
'type'=>'left',
|
||||
'titre'=>'New Calendar',
|
||||
'mainmenu'=>'bookcal',
|
||||
'leftmenu'=>'bookcal_calendar',
|
||||
'titre'=>'NewCalendar',
|
||||
'mainmenu'=>'agenda',
|
||||
'leftmenu'=>'bookcal_new',
|
||||
'url'=>'/bookcal/calendar_card.php?action=create',
|
||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'langs'=>'bookcal',
|
||||
|
|
@ -405,11 +420,11 @@ class modBookCal extends DolibarrModules
|
|||
|
||||
$this->menu[$r++]=array(
|
||||
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'fk_menu'=>'fk_mainmenu=bookcal',
|
||||
'fk_menu'=>'fk_mainmenu=agenda,fk_leftmenu=bookcal',
|
||||
// This is a Left menu entry
|
||||
'type'=>'left',
|
||||
'titre'=>'List Availabilities',
|
||||
'mainmenu'=>'bookcal',
|
||||
'titre'=>'Availabilities',
|
||||
'mainmenu'=>'agenda',
|
||||
'leftmenu'=>'bookcal_availabilities',
|
||||
'url'=>'/bookcal/availabilities_list.php',
|
||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
|
|
@ -425,11 +440,11 @@ class modBookCal extends DolibarrModules
|
|||
);
|
||||
$this->menu[$r++]=array(
|
||||
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'fk_menu'=>'fk_mainmenu=bookcal,fk_leftmenu=bookcal_availabilities',
|
||||
'fk_menu'=>'fk_mainmenu=agenda,fk_leftmenu=bookcal_availabilities',
|
||||
// This is a Left menu entry
|
||||
'type'=>'left',
|
||||
'titre'=>'New Availabilities',
|
||||
'mainmenu'=>'bookcal',
|
||||
'titre'=>'NewAvailabilities',
|
||||
'mainmenu'=>'agenda',
|
||||
'leftmenu'=>'bookcal_availabilities',
|
||||
'url'=>'/bookcal/availabilities_card.php?action=create',
|
||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
|
|
|
|||
|
|
@ -180,4 +180,5 @@ BrowserPush=Browser Popup Notification
|
|||
Reminders=Reminders
|
||||
ActiveByDefault=Enabled by default
|
||||
Until=until
|
||||
DataFromWasMerged=Data from %s was merged
|
||||
DataFromWasMerged=Data from %s was merged
|
||||
AgendaShowBookcalCalendar=Booking calendar: %s
|
||||
|
|
@ -44,6 +44,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
|||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
|
||||
|
||||
$langs->loadLangs(array("main", "other", "dict", "agenda", "errors", "companies"));
|
||||
|
||||
|
|
@ -169,13 +171,21 @@ function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $
|
|||
|
||||
if ($action == 'add') {
|
||||
$error = 0;
|
||||
$urlback = '';
|
||||
$idcontact = 0;
|
||||
$calendar = new Calendar($db);
|
||||
$contact = new Contact($db);
|
||||
$actioncomm = new ActionComm($db);
|
||||
|
||||
$res = $calendar->fetch($fk_calendar);
|
||||
if ($res < 0) {
|
||||
$error++;
|
||||
$errmsg .= $calendar->error." ".join(',', $calendar->errors);
|
||||
}
|
||||
|
||||
if (!is_object($user)) {
|
||||
$user = new User($db);
|
||||
}
|
||||
|
||||
$booking = new ActionComm($db);
|
||||
|
||||
$db->begin();
|
||||
if (!GETPOST("lastname")) {
|
||||
$error++;
|
||||
|
|
@ -191,21 +201,71 @@ if ($action == 'add') {
|
|||
}
|
||||
|
||||
if (!$error) {
|
||||
$booking->ref = $booking->getNextNumRef();
|
||||
$booking->lastname = GETPOST("lastname");
|
||||
$booking->firstname = GETPOST("firstname");
|
||||
$booking->email = GETPOST("email");
|
||||
$booking->description = GETPOST("description");
|
||||
$booking->duration = GETPOST("duration");
|
||||
$booking->start = GETPOST("datetimebooking", 'int');
|
||||
$booking->fk_bookcal_availability = GETPOST("id", 'int');
|
||||
$sql = "SELECT s.rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as s";
|
||||
$sql .= " WHERE s.lastname = '".GETPOST("lastname")."'";
|
||||
$sql .= " AND s.firstname = '".GETPOST("firstname")."'";
|
||||
$sql .= " AND s.email = '".GETPOST("email")."'";
|
||||
$resql = $db->query($sql);
|
||||
|
||||
$result = $booking->create($user);
|
||||
if ($result <= 0) {
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$idcontact = $obj->rowid;
|
||||
$contact->fetch($idcontact);
|
||||
} else {
|
||||
$contact->lastname = GETPOST("lastname");
|
||||
$contact->firstname = GETPOST("firstname");
|
||||
$contact->email = GETPOST("email");
|
||||
$result = $contact->create($user);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errmsg .= $contact->error." ".join(',', $contact->errors);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$errmsg = ($booking->error ? $booking->error.'<br>' : '').join('<br>', $booking->errors);
|
||||
$errmsg .= $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$dateend = dol_time_plus_duree(GETPOST("datetimebooking", 'int'), GETPOST("duration"), 'i');
|
||||
|
||||
$actioncomm->label = "test";
|
||||
$actioncomm->type = 'AC_RDV';
|
||||
$actioncomm->type_id = 5;
|
||||
$actioncomm->datep = GETPOST("datetimebooking", 'int');
|
||||
$actioncomm->datef = $dateend;
|
||||
$actioncomm->note_private = GETPOST("description");
|
||||
$actioncomm->percentage = -1;
|
||||
$actioncomm->fk_bookcal_availability = GETPOST("id", 'int');
|
||||
$actioncomm->userownerid = $calendar->visibility;
|
||||
$actioncomm->contact_id = $contact->id;
|
||||
$actioncomm->socpeopleassigned = $contact->id;
|
||||
$result = $actioncomm->create($user);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errmsg .= $actioncomm->error." ".join(',', $actioncomm->errors);
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources";
|
||||
$sql .= "(fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= (int) $actioncomm->id;
|
||||
$sql .= ", 'socpeople'";
|
||||
$sql .= ", ". (int) $contact->id;
|
||||
$sql .= ", 0, 0, 0)";
|
||||
$resql = $db->query($sql);
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
$errmsg .= $db->lasterror();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$action = 'afteradd';
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ print '<div class="bookcalpublicarea centpercent" style="position:absolute;top:5
|
|||
print '<div class="bookcalform center" style="width:70%;padding:5px;max-height:360px">';
|
||||
print '<h2>'.(!empty($object->label) ? $object->label : $object->ref).'</h2>';
|
||||
|
||||
$sql = "SELECT b.rowid, b.ref, b.label, b.start, b.end, b.duration, b.startHour, b.endHour";
|
||||
$sql = "SELECT b.rowid, b.label, b.start, b.end, b.duration, b.startHour, b.endHour";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."bookcal_availabilities as b";
|
||||
$sql .= " WHERE b.status = ".(int) $availabilities::STATUS_VALIDATED;
|
||||
$sql .= " AND b.fk_bookcal_calendar = ".(int) $id;
|
||||
|
|
@ -193,7 +193,7 @@ if ($resql) {
|
|||
while ($i < $num) {
|
||||
$i++;
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<a href="'.DOL_URL_ROOT.'/public/bookcal/booking.php?id='.$obj->rowid.'&fk_calendar='.$id.'"><button type="button">'.(!empty($obj->label) ? $obj->label : $obj->ref).'</button>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/public/bookcal/booking.php?id='.$obj->rowid.'&fk_calendar='.$id.'"><button type="button">'.(!empty($obj->label) ? $obj->label : $obj->id).'</button>';
|
||||
}
|
||||
}
|
||||
print '</div>';
|
||||
|
|
|
|||
Loading…
Reference in a new issue