示例#1
0
 protected function action_removeAllRecurrences()
 {
     if (!empty($this->bean->repeat_parent_id)) {
         $id = $this->bean->repeat_parent_id;
         $this->bean->retrieve($id);
     } else {
         $id = $this->bean->id;
     }
     if (!$this->bean->ACLAccess('Delete')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     require_once "modules/Calendar/CalendarUtils.php";
     CalendarUtils::markRepeatDeleted($this->bean);
     $this->bean->mark_deleted($id);
     header("Location: index.php?module=Meetings");
 }
示例#2
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $timeArray array of datetimes
  * @return array
  */
 static function saveRecurring(SugarBean $bean, $timeArray)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     $db = $GLOBALS['db'];
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     // If the bean has a users_arr then related records for those ids will have
     // already been created. This prevents duplicates of those records for
     // users, contacts and leads (handled below)
     $exclude_users = empty($bean->users_arr) ? array() : array_flip($bean->users_arr);
     while ($ro = $db->fetchByAssoc($re)) {
         if (!isset($exclude_users[$ro['user_id']])) {
             $users_rel_arr[] = $ro['user_id'];
         }
     }
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_contacts = array();
     $qu_users = array();
     $qu_leads = array();
     $arr = array();
     $i = 0;
     Activity::disable();
     $clone = clone $bean;
     //this is a new bean being created - so throw away cloned fetched_row
     //attribute that incorrectly makes it look like an existing bean
     $clone->fetched_row = false;
     foreach ($timeArray as $date_start) {
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 $qu_users[] = array('id' => create_guid(), 'user_id' => $user_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 $qu_contacts[] = array('id' => create_guid(), 'contact_id' => $contact_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($leads_rel_arr as $lead_id) {
                 $qu_leads[] = array('id' => create_guid(), 'lead_id' => $lead_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     Activity::enable();
     if (!empty($qu_users)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'user_id' => array('name' => 'user_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_users as $qu_user) {
             $db->insertParams($bean->rel_users_table, $fields, $qu_user);
         }
     }
     if (!empty($qu_contacts)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'contact_id' => array('name' => 'contact_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_contacts as $qu_contact) {
             $db->insertParams($bean->rel_contacts_table, $fields, $qu_contact);
         }
     }
     if (!empty($qu_leads)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'lead_id' => array('name' => 'lead_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_leads as $qu_lead) {
             $db->insertParams($bean->rel_leads_table, $fields, $qu_lead);
         }
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
示例#3
0
 function mark_deleted($id)
 {
     require_once "modules/Calendar/CalendarUtils.php";
     CalendarUtils::correctRecurrences($this, $id);
     global $current_user;
     parent::mark_deleted($id);
     if ($this->update_vcal) {
         vCal::cache_sugar_vcal($current_user);
     }
 }
示例#4
0
 /**
  * Prepare recurring sequence if needed.
  * @return bool true if recurring records need to be created
  */
 public function prepareRecurring()
 {
     require_once "modules/Calendar/CalendarUtils.php";
     if (empty($_REQUEST['edit_all_recurrences'])) {
         $repeatFields = array('type', 'interval', 'count', 'until', 'dow', 'parent_id');
         foreach ($repeatFields as $param) {
             unset($_POST['repeat_' . $param]);
         }
     } else {
         if (!empty($_REQUEST['repeat_type']) && !empty($_REQUEST['date_start'])) {
             $params = array('type' => $_REQUEST['repeat_type'], 'interval' => $_REQUEST['repeat_interval'], 'count' => $_REQUEST['repeat_count'], 'until' => $_REQUEST['repeat_until'], 'dow' => $_REQUEST['repeat_dow']);
             $this->repeatDataArray = CalendarUtils::buildRecurringSequence($_REQUEST['date_start'], $params);
             return true;
         }
     }
     return false;
 }
示例#5
0
 /**
  * Get date string of next or previous calendar grid
  * @param string $direction next or previous
  * @return string
  */
 public function get_neighbor_date_str($direction)
 {
     if ($direction == "previous") {
         $sign = "-";
     } else {
         $sign = "+";
     }
     if ($this->view == 'month') {
         $day = $this->date_time->get_day_by_index_this_month(0)->get($sign . "1 month")->get_day_begin(1);
     } else {
         if ($this->view == 'week' || $this->view == 'shared') {
             $day = CalendarUtils::get_first_day_of_week($this->date_time);
             $day = $day->get($sign . "7 days");
         } else {
             if ($this->view == 'day') {
                 $day = $this->date_time->get($sign . "1 day")->get_day_begin();
             } else {
                 if ($this->view == 'year') {
                     $day = $this->date_time->get($sign . "1 year")->get_day_begin();
                 } else {
                     $calendarStrings = return_module_language($GLOBALS['current_language'], 'Calendar');
                     return $calendarStrings['ERR_NEIGHBOR_DATE'];
                 }
             }
         }
     }
     return $day->get_date_str();
 }
示例#6
0
 /**
  * Action Remove
  */
 protected function action_remove()
 {
     $this->view = 'json';
     if (!$this->retrieveCurrentBean('Delete')) {
         return;
     }
     if ($this->currentBean->module_dir == "Meetings" || $this->currentBean->module_dir == "Calls") {
         if (!empty($_REQUEST['remove_all_recurrences']) && $_REQUEST['remove_all_recurrences']) {
             CalendarUtils::markRepeatDeleted($this->currentBean);
         }
     }
     $this->currentBean->mark_deleted($_REQUEST['record']);
     $this->view_object_map['jsonData'] = array('access' => 'yes');
 }
示例#7
0
 /**
  * Get html of year calendar
  * @return string
  */
 protected function display_year()
 {
     $weekEnd1 = 0 - $this->startday;
     $weekEnd2 = -1 - $this->startday;
     if ($weekEnd1 < 0) {
         $weekEnd1 += 7;
     }
     if ($weekEnd2 < 0) {
         $weekEnd2 += 7;
     }
     $year_start = $GLOBALS['timedate']->fromString($this->cal->date_time->year . '-01-01');
     $str = "";
     $str .= '<table id="daily_cal_table" cellspacing="1" cellpadding="0" border="0" width="100%">';
     for ($m = 0; $m < 12; $m++) {
         $month_start = $year_start->get("+" . $m . " months");
         $month_start_ts = $month_start->format('U') + $month_start->getOffset();
         $month_end = $month_start->get("+" . $month_start->format('t') . " days");
         $week_start = CalendarUtils::get_first_day_of_week($month_start);
         $week_start_ts = $week_start->format('U') + $week_start->getOffset();
         // convert to timestamp, ignore tz
         $month_end_ts = $month_end->format('U') + $month_end->getOffset();
         $table_id = "daily_cal_table" . $m;
         //bug 47471
         if ($m % 3 == 0) {
             $str .= "<tr>";
         }
         $str .= '<td class="yearCalBodyMonth" align="center" valign="top" scope="row">';
         $str .= '<a class="yearCalBodyMonthLink" href="' . ajaxLink('index.php?module=Calendar&action=index&view=month&&hour=0&day=1&month=' . ($m + 1) . '&year=' . $GLOBALS['timedate']->fromTimestamp($month_start_ts)->format('Y')) . '">' . $GLOBALS['app_list_strings']['dom_cal_month_long'][$m + 1] . '</a>';
         $str .= '<table id="' . $table_id . '" cellspacing="1" cellpadding="0" border="0" width="100%">';
         $str .= '<tr class="monthCalBodyTH">';
         for ($d = 0; $d < 7; $d++) {
             $str .= '<th width="14%">' . $this->weekdays[$d] . '</th>';
         }
         $str .= '</tr>';
         $curr_time_global = $week_start_ts;
         $w = 0;
         while ($curr_time_global < $month_end_ts) {
             $str .= '<tr class="monthViewDayHeight yearViewDayHeight">';
             for ($d = 0; $d < 7; $d++) {
                 $curr_time = $week_start_ts + $d * 86400 + $w * 60 * 60 * 24 * 7;
                 if ($curr_time < $month_start_ts || $curr_time >= $month_end_ts) {
                     $monC = "";
                 } else {
                     $monC = '<a href="' . ajaxLink('index.php?module=Calendar&action=index&view=day&hour=0&day=' . $GLOBALS['timedate']->fromTimestamp($curr_time)->format('j') . '&month=' . $GLOBALS['timedate']->fromTimestamp($curr_time)->format('n') . '&year=' . $GLOBALS['timedate']->fromTimestamp($curr_time)->format('Y')) . '">' . $GLOBALS['timedate']->fromTimestamp($curr_time)->format('j') . '</a>';
                 }
                 if ($d == $weekEnd1 || $d == $weekEnd2) {
                     $str .= "<td class='weekEnd monthCalBodyWeekEnd'>";
                 } else {
                     $str .= "<td class='monthCalBodyWeekDay'>";
                 }
                 $str .= $monC;
                 $str .= "</td>";
             }
             $str .= "</tr>";
             $curr_time_global += 60 * 60 * 24 * 7;
             $w++;
         }
         $str .= '</table>';
         $str .= '</td>';
         if (($m - 2) % 3 == 0) {
             $str .= "</tr>";
         }
     }
     $str .= "</table>";
     return $str;
 }
示例#8
0
 /**
  ** Affiche le transporteur Dejala.fr dans la liste des transporteurs sur le Front Office
  */
 public function hookExtraCarrier($params)
 {
     global $smarty, $cart, $cookie, $defaultCountry;
     $this->hooklog("ExtraCarrier", $params);
     // Dejala n'est pas actif sur la boutique
     if ($this->dejalaConfig->active != 1) {
         return;
     }
     $djlUtil = new DejalaUtils();
     $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store);
     if ($responseGetStore['status'] != '200') {
         return;
     }
     $isCartOutOfStock = '0';
     if ($this->isCartOutOfStock()) {
         $isCartOutOfStock = '1';
     }
     $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . '');
     $acceptPartial = true;
     if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || $store['attributes']['delivery_partial'] != '1') {
         $acceptPartial = false;
     }
     if ($isCartOutOfStock == '1' && !$acceptPartial) {
         return;
     }
     $totalCartWeight = floatval($cart->getTotalWeight());
     $address = $params['address'];
     // ask dejala.fr for a quotation
     $quotation["receiver_name"] = $address->lastname;
     $quotation["receiver_firstname"] = $address->firstname;
     $quotation["receiver_company"] = $address->company;
     $quotation["receiver_address"] = $address->address1;
     $quotation["receiver_address2"] = $address->address2;
     $quotation["receiver_zipcode"] = $address->postcode;
     $quotation["receiver_city"] = $address->city;
     $quotation["receiver_phone"] = $address->phone;
     $quotation["receiver_phone_mobile"] = $address->phone_mobile;
     $quotation["receiver_comments"] = $address->other;
     $quotation["timelimit"] = 3;
     $quotation["weight"] = $totalCartWeight;
     $this->mylog("asking for quotation=" . $this->logValue($quotation, 1));
     $products = array();
     $responseArray = $djlUtil->getStoreQuotation($this->dejalaConfig, $quotation, $products);
     if ($responseArray['status'] != '200') {
         return;
     }
     $this->mylog("found quotation=" . $this->logValue($responseArray['response'], 1));
     $electedProduct = NULL;
     foreach ($products as $key => $product) {
         //	if (floatval($product['max_weight']) >= $totalCartWeight) {
         if (is_null($electedProduct) || intval($electedProduct['priority']) > intval($key)) {
             $electedProduct = $product;
         }
         //	}
     }
     if (is_null($electedProduct)) {
         return;
     }
     $this->mylog("electedProduct=" . $this->logValue($electedProduct, 1));
     $electedCarrier = DejalaCarrierUtils::getDejalaCarrier($this->dejalaConfig, $electedProduct);
     $this->mylog("electedCarrier=" . $this->logValue($electedCarrier, 1));
     if (null == $electedCarrier) {
         $this->mylog("creating a new carrier");
         $electedCarrier = DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig, $electedProduct);
     }
     // Calcul des dates dispo
     $productCalendar = $electedProduct['calendar']['entries'];
     // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time
     if ($electedProduct['pickingtime']) {
         $pickingtime = intval($electedProduct['pickingtime']);
     } else {
         $pickingtime = $electedProduct['timelimit'];
     }
     $djlUtil = new DejalaUtils();
     $storeCalendar = array();
     $calendar = array();
     $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar);
     $this->mylog("productCalendar=" . $this->logValue($productCalendar, 1));
     $this->mylog("storeCalendar=" . $this->logValue($storeCalendar, 1));
     $this->mylog("response['status']=" . $response['status']);
     if ($response['status'] == 200) {
         foreach ($storeCalendar['entries'] as $weekday => $calEntry) {
             if (isset($productCalendar[$weekday])) {
                 $calendar[$weekday]["weekday"] = $weekday;
                 $calendar[$weekday]["start_hour"] = max(intval($productCalendar[$weekday]["start_hour"]), intval($calEntry["start_hour"]));
                 // MFR090831 - manage picking time : the store is open to (stop_hour - picking time)
                 $calendar[$weekday]["stop_hour"] = min(intval($productCalendar[$weekday]["stop_hour"] - 1), intval($calEntry["stop_hour"] - $pickingtime));
                 if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) {
                     unset($calendar[$weekday]);
                 }
             }
         }
     }
     // Calcul de la date de démarrage pour les créneaux :
     // Avancement jusque jour dispo & ouvert
     // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours
     // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00
     $deliveryDelay = $store['attributes']['delivery_delay'];
     $calUtils = new CalendarUtils();
     $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']);
     $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions);
     if ($dateUtc == NULL) {
         return;
     }
     if ($deliveryDelay > 0) {
         $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions);
     }
     if ($dateUtc == NULL) {
         return;
     }
     $dateUtc = $calUtils->adjustHour($dateUtc, $calendar);
     $this->mylog("calendar=" . $this->logValue($calendar, 1));
     $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc), 1));
     /**
     		 Dates[0] = {
     		 [label]=lundi
     		 [value]=23/04/2009
     		 [start_hour]=9
     		 [stop_hour]=17
     		 }
     		 **/
     $today = getDate();
     $ctime = time();
     $wday_labels = array($this->l('Dimanche'), $this->l('Lundi'), $this->l('Mardi'), $this->l('Mercredi'), $this->l('Jeudi'), $this->l('Vendredi'), $this->l('Samedi'));
     $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed'];
     $iDate = 0;
     $dates = array();
     $balladUtc = $dateUtc;
     do {
         $dates[$iDate]['value'] = date("Y/m/d", $balladUtc);
         $wd = date("w", $balladUtc);
         $dates[$iDate]['label'] = $wday_labels[$wd] . " " . date("j", $balladUtc);
         $dates[$iDate]['start_hour'] = $calendar[$wd]['start_hour'];
         $dates[$iDate]['stop_hour'] = $calendar[$wd]['stop_hour'];
         $balladUtc += 3600 * 24;
         $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions);
         $iDate++;
     } while ($iDate < $nbDeliveryDates && $balladUtc);
     // impossibilité de trouver un jour dispo
     if (!isset($dates[0])) {
         return;
     }
     $dates[0]['start_hour'] = date("H", $dateUtc);
     $this->mylog("date\$=" . $this->logValue($dates, 1));
     $smarty->assign('nb_days', $nbDeliveryDates);
     $smarty->assign('dates', $dates);
     for ($i = 0; $i < 24; $i++) {
         $endHour = ($i + $electedProduct['timelimit']) % 24;
         if ($endHour == 0) {
             $endHour = 24;
         }
         $hourLabels[] = $i . 'h-' . $endHour . 'h';
     }
     $smarty->assign('hourLabels', $hourLabels);
     $smarty->assign('timetable_css', _MODULE_DIR_ . $this->name . '/timetable.css');
     $smarty->assign("timetable_js", _MODULE_DIR_ . $this->name . '/timetable.js');
     $this->mylog("electedCarrier->id=" . $this->logValue($electedCarrier->id));
     $mCarrier = $electedCarrier;
     $row['id_carrier'] = intval($electedCarrier->id);
     $row['name'] = $this->l('Dejala.fr');
     $row['delay'] = $electedCarrier->delay[$cookie->id_lang];
     $row['price'] = $cart->getOrderShippingCost($electedCarrier->id);
     $row['price_tax_exc'] = $cart->getOrderShippingCost($electedCarrier->id, false);
     $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif';
     $resultsArray[] = $row;
     $smarty->assign('carriers', $resultsArray);
     if ($cart->id_carrier) {
         $smarty->assign('checked', $cart->id_carrier);
     }
     $smarty->assign('product', $electedProduct);
     $djlCart = new DejalaCart($cart->id);
     $setDefaultDate = TRUE;
     if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) {
         $mShippingDate = $djlCart->shipping_date;
         $this->mylog("shipping_date=" . $this->logValue($mShippingDate));
         $m_day = date("d", $mShippingDate);
         $m_hour = date("H", $mShippingDate);
         $deliveryDateSelected = date("Y/m/d", $mShippingDate);
         $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected));
         foreach ($dates as $l_key => $l_date) {
             if ($l_date['value'] == $deliveryDateSelected) {
                 $smarty->assign("deliveryDateIndexSelected", $l_key);
                 $smarty->assign("deliveryDateSelected", $deliveryDateSelected);
                 $smarty->assign("deliveryHourSelected", $m_hour);
                 $setDefaultDate = FALSE;
             }
         }
     }
     if ($setDefaultDate) {
         $smarty->assign("deliveryDateIndexSelected", 0);
         $smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc));
         $smarty->assign("deliveryHourSelected", intval(date("H", $dateUtc)));
     }
     $smarty->assign("isCartOutOfStock", $isCartOutOfStock);
     if (!$isCartOutOfStock) {
         $buffer = $this->display(__FILE__, 'dejala_carrier.tpl');
         $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl');
     } else {
         $smarty->assign('nostock_info', $this->l(utf8_encode('Je choisirai mon heure de livraison quand mon colis sera prêt.')));
         $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl');
     }
     return $buffer;
 }
示例#9
0
 /**
  ** Affiche le transporteur Dejala.com dans la liste des transporteurs sur le Front Office
  */
 public function hookExtraCarrier($params)
 {
     global $smarty, $defaultCountry;
     $cart = $params['cart'];
     $cookie = $params['cookie'];
     $this->hooklog("ExtraCarrier", $params);
     // Check if Dejala should be visible
     if ($this->dejalaConfig->visibility_status == "invisible") {
         return;
     }
     if ($this->dejalaConfig->visibility_status == "visible_limited" && (int) $cookie->id_customer > 0) {
         $customer = new Customer((int) $cookie->id_customer);
         if (!in_array($customer->email, preg_split("/[\\s,]+/", $this->dejalaConfig->visible_users_list))) {
             return;
         }
     }
     $djlUtil = new DejalaUtils();
     $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store);
     if ($responseGetStore['status'] != '200') {
         return;
     }
     $isCartOutOfStock = '0';
     if ($this->isCartOutOfStock($cart)) {
         $isCartOutOfStock = '1';
     }
     $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . '');
     $acceptPartial = true;
     if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || $store['attributes']['delivery_partial'] != '1') {
         $acceptPartial = false;
     }
     if ($isCartOutOfStock == '1' && !$acceptPartial) {
         return;
     }
     $electedProduct = $this->getDejalaProduct($cart);
     // Get id zone
     if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
         $id_zone = (int) Address::getZoneById((int) $cart->id_address_delivery);
     } else {
         $id_zone = (int) $defaultCountry->id_zone;
     }
     $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name);
     $this->mylog("electedCarrier=" . $this->logValue($djlCarrier, 1));
     if ($djlCarrier == null) {
         return null;
     }
     // Calcul des dates dispo
     $productCalendar = $electedProduct['calendar']['entries'];
     // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time
     if ($electedProduct['pickingtime']) {
         $pickingtime = (int) $electedProduct['pickingtime'];
     } else {
         $pickingtime = $electedProduct['timelimit'];
     }
     $djlUtil = new DejalaUtils();
     $storeCalendar = array();
     $calendar = array();
     $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar);
     $this->mylog("productCalendar=" . $this->logValue($productCalendar, 1));
     $this->mylog("storeCalendar=" . $this->logValue($storeCalendar, 1));
     $this->mylog("response['status']=" . $response['status']);
     if ($response['status'] == 200) {
         foreach ($storeCalendar['entries'] as $weekday => $calEntry) {
             if (isset($productCalendar[$weekday])) {
                 $calendar[$weekday]["weekday"] = $weekday;
                 $calendar[$weekday]["start_hour"] = max((int) $productCalendar[$weekday]["start_hour"], (int) $calEntry["start_hour"]);
                 // MFR090831 - manage picking time : the store is open to (stop_hour - picking time)
                 $calendar[$weekday]["stop_hour"] = min((int) ($productCalendar[$weekday]["stop_hour"] - 1), (int) ($calEntry["stop_hour"] - $pickingtime));
                 if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) {
                     unset($calendar[$weekday]);
                 }
             }
         }
     }
     // Calcul de la date de démarrage pour les créneaux :
     // Avancement jusque jour dispo & ouvert
     // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours
     // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00
     $deliveryDelay = $store['attributes']['delivery_delay'];
     $skipCurDay = false;
     $calUtils = new CalendarUtils();
     $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']);
     $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions);
     if ($dateUtc == NULL) {
         return;
     }
     if ($deliveryDelay > 0) {
         if ($skipCurDay) {
             $dateUtc = $calUtils->skipCurDay($dateUtc);
         }
         $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions);
     }
     if ($dateUtc == NULL) {
         return;
     }
     $dateUtc = $calUtils->adjustHour($dateUtc, $calendar);
     $this->mylog("calendar=" . $this->logValue($calendar, 1));
     $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc), 1));
     $today = getDate();
     $ctime = time();
     $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed'];
     $iDate = 0;
     $dates = array();
     $balladUtc = $dateUtc;
     do {
         $wd = date("w", $balladUtc);
         if ((int) $calendar[$wd]['stop_hour'] < (int) $calendar[$wd]['start_hour']) {
             continue;
         }
         $dates[$iDate]['value'] = date("Y/m/d", $balladUtc);
         $dates[$iDate]['ts'] = $balladUtc;
         $dates[$iDate]['label'] = $this->wday_labels[$wd] . " " . date("j", $balladUtc);
         $dates[$iDate]['start_hour'] = (int) $calendar[$wd]['start_hour'];
         $dates[$iDate]['stop_hour'] = (int) $calendar[$wd]['stop_hour'];
         $balladUtc = strtotime(date("Y-m-d", $balladUtc) . " +1 day");
         $balladUtc = mktime(0, 0, 0, date('m', $balladUtc), date('d', $balladUtc), date('Y', $balladUtc));
         $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions);
         $iDate++;
     } while ($iDate < $nbDeliveryDates && $balladUtc);
     // impossibilité de trouver un jour dispo
     if (!isset($dates[0])) {
         return;
     }
     $now = (int) date("H", $ctime);
     if ((int) $dates[0]['stop_hour'] > $now && (int) $dates[0]['start_hour'] < $now) {
         $dates[0]['start_hour'] = $now;
     } elseif ((int) $dates[0]['ts'] == $now && (int) $dates[0]['stop_hour'] < $now) {
         array_shift($dates);
     }
     $this->mylog("date\$=" . $this->logValue($dates, 1));
     $smarty->assign('nb_days', $nbDeliveryDates);
     $smarty->assign('dates', $dates);
     for ($i = 0; $i < 24; $i++) {
         $endHour = ($i + $electedProduct['timelimit']) % 24;
         if ($endHour == 0) {
             $endHour = 24;
         }
         $hourLabels[] = $i . 'h-' . $endHour . 'h';
     }
     $smarty->assign('hourLabels', $hourLabels);
     $smarty->assign('timetable_css', _MODULE_DIR_ . $this->name . '/timetable.css');
     $smarty->assign("timetable_js", _MODULE_DIR_ . $this->name . '/timetable.js');
     $this->mylog("electedCarrier->id=" . $this->logValue($djlCarrier->id));
     $mCarrier = $djlCarrier;
     $row['id_carrier'] = (int) $djlCarrier->id;
     $row['name'] = $this->l('Dejala.com');
     $row['delay'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'] . 'H';
     $row['price'] = $cart->getOrderShippingCost($djlCarrier->id);
     $row['price_tax_exc'] = $cart->getOrderShippingCost($djlCarrier->id, false);
     $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif';
     $resultsArray[] = $row;
     $smarty->assign('carriers', $resultsArray);
     $smarty->assign('my_carrier_selected', isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id);
     $smarty->assign('product', $electedProduct);
     $djlCart = new DejalaCart($cart->id);
     $setDefaultDate = TRUE;
     if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) {
         $mShippingDate = $djlCart->shipping_date;
         $this->mylog("shipping_date=" . $this->logValue($mShippingDate));
         $m_day = date("d", $mShippingDate);
         $m_hour = date("H", $mShippingDate);
         $deliveryDateSelected = date("Y/m/d", $mShippingDate);
         $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected));
         foreach ($dates as $l_key => $l_date) {
             if ($l_date['value'] == $deliveryDateSelected) {
                 $smarty->assign("deliveryDateIndexSelected", $l_key);
                 $smarty->assign("deliveryDateSelected", $deliveryDateSelected);
                 $smarty->assign("deliveryHourSelected", $m_hour);
                 $setDefaultDate = FALSE;
             }
         }
     }
     if ($setDefaultDate) {
         $smarty->assign("deliveryDateIndexSelected", 0);
         $smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc));
         $smarty->assign("deliveryHourSelected", (int) date("H", $dateUtc));
     }
     $smarty->assign("isCartOutOfStock", $isCartOutOfStock);
     if (!$isCartOutOfStock) {
         $buffer = $this->display(__FILE__, 'dejala_carrier.tpl');
         $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl');
     } else {
         $smarty->assign('nostock_info', $this->l('I will select my shipping date when my product is available.'));
         $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl');
     }
     return $buffer;
 }
示例#10
0
 public function display()
 {
     require_once "modules/Calendar/CalendarUtils.php";
     $module = $this->view_object_map['currentModule'];
     $_REQUEST['module'] = $module;
     $base = 'modules/' . $module . '/metadata/';
     $source = 'custom/' . $base . 'quickcreatedefs.php';
     if (!file_exists($source)) {
         $source = $base . 'quickcreatedefs.php';
         if (!file_exists($source)) {
             $source = 'custom/' . $base . 'editviewdefs.php';
             if (!file_exists($source)) {
                 $source = $base . 'editviewdefs.php';
             }
         }
     }
     $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], $module);
     $tpl = $this->getCustomFilePathIfExists('include/EditView/EditView.tpl');
     $this->ev = new EditView();
     $this->ev->view = "QuickCreate";
     $this->ev->ss = new Sugar_Smarty();
     $this->ev->formName = "CalendarEditView";
     $this->ev->setup($module, $this->bean, $source, $tpl);
     $this->ev->defs['templateMeta']['form']['headerTpl'] = "modules/Calendar/tpls/editHeader.tpl";
     $this->ev->defs['templateMeta']['form']['footerTpl'] = "modules/Calendar/tpls/empty.tpl";
     $this->ev->process(false, "CalendarEditView");
     if (!empty($this->bean->id)) {
         require_once 'include/json_config.php';
         global $json;
         $json = getJSONobj();
         $json_config = new json_config();
         $GRjavascript = $json_config->getFocusData($module, $this->bean->id);
     } else {
         $GRjavascript = "";
     }
     $json_arr = array('access' => 'yes', 'module_name' => $this->bean->module_dir, 'record' => $this->bean->id, 'edit' => $this->editable, 'html' => $this->ev->display(false, true), 'gr' => $GRjavascript);
     if ($repeat_arr = CalendarUtils::get_sendback_repeat_data($this->bean)) {
         $json_arr = array_merge($json_arr, array("repeat" => $repeat_arr));
     }
     ob_clean();
     echo json_encode($json_arr);
 }
示例#11
0
 /**
  * Get date string of next or previous calendar grid
  * @param string $direction next or previous
  * @return string
  */
 public function get_neighbor_date_str($direction)
 {
     if ($direction == "previous") {
         $sign = "-";
     } else {
         $sign = "+";
     }
     if ($this->view == 'month') {
         $day = $this->date_time->get_day_by_index_this_month(0)->get($sign . "1 month")->get_day_begin(1);
     } else {
         if ($this->view == 'week' || $this->view == 'shared') {
             $day = CalendarUtils::get_first_day_of_week($this->date_time);
             $day = $day->get($sign . "7 days");
         } else {
             if ($this->view == 'day') {
                 $day = $this->date_time->get($sign . "1 day")->get_day_begin();
             } else {
                 if ($this->view == 'year') {
                     $day = $this->date_time->get($sign . "1 year")->get_day_begin();
                 } else {
                     return "get_neighbor_date_str: notdefined for this view";
                 }
             }
         }
     }
     return $day->get_date_str();
 }
示例#12
0
 /**
  * Get date info string (legacy from old calendar)
  * @return string
  */
 public function get_date_info($view, $date_time)
 {
     $str = "";
     global $current_user;
     $dateFormat = $current_user->getUserDateTimePreferences();
     if ($view == 'month') {
         for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
             switch ($dateFormat['date'][$i]) {
                 case "Y":
                     $str .= " " . $date_time->year;
                     break;
                 case "m":
                     $str .= " " . $date_time->get_month_name();
                     break;
             }
         }
     } else {
         if ($view == 'week' || $view == 'shared') {
             $first_day = $date_time;
             $first_day = CalendarUtils::get_first_day_of_week($date_time);
             $last_day = $first_day->get("+6 days");
             for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                 switch ($dateFormat['date'][$i]) {
                     case "Y":
                         $str .= " " . $first_day->year;
                         break;
                     case "m":
                         $str .= " " . $first_day->get_month_name();
                         break;
                     case "d":
                         $str .= " " . $first_day->get_day();
                         break;
                 }
             }
             $str .= " - ";
             for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                 switch ($dateFormat['date'][$i]) {
                     case "Y":
                         $str .= " " . $last_day->year;
                         break;
                     case "m":
                         $str .= " " . $last_day->get_month_name();
                         break;
                     case "d":
                         $str .= " " . $last_day->get_day();
                         break;
                 }
             }
         } else {
             if ($view == 'day') {
                 $str .= $date_time->get_day_of_week() . " ";
                 for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                     switch ($dateFormat['date'][$i]) {
                         case "Y":
                             $str .= " " . $date_time->year;
                             break;
                         case "m":
                             $str .= " " . $date_time->get_month_name();
                             break;
                         case "d":
                             $str .= " " . $date_time->get_day();
                             break;
                     }
                 }
             } else {
                 if ($view == 'year') {
                     $str .= $date_time->year;
                 } else {
                     sugar_die("echo_date_info: date not supported");
                 }
             }
         }
     }
     return $str;
 }
示例#13
0
 /**
  * Deletes the child recurrences of the given bean
  *
  * @param $bean
  */
 public function deleteRecurrences($bean)
 {
     CalendarUtils::markRepeatDeleted($bean);
 }
示例#14
0
 /**
  * @param SugarBean $parentBean
  * @param array $repeatDateTimeArray
  * @return array events saved
  */
 protected function saveRecurring(SugarBean $parentBean, array $repeatDateTimeArray)
 {
     // Load the user relationship so the child events that are created will
     // have the users added via bean->save (which has special auto-accept
     // logic)
     if ($parentBean->load_relationship('users')) {
         $parentBean->users_arr = $parentBean->users->get();
     }
     return CalendarUtils::saveRecurring($parentBean, $repeatDateTimeArray);
 }
示例#15
0
 /**
  * Get date info string (legacy from old calendar)
  * @return string
  */
 public function get_date_info($view, $date_time)
 {
     $str = "";
     global $current_user;
     $dateFormat = $current_user->getUserDateTimePreferences();
     if ($view == 'month' || $view == 'sharedMonth') {
         for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
             switch ($dateFormat['date'][$i]) {
                 case "Y":
                     $str .= " " . $date_time->year;
                     break;
                 case "m":
                     $str .= " " . $date_time->get_month_name();
                     break;
             }
         }
     } else {
         if ($view == 'agendaWeek' || $view == 'sharedWeek') {
             $first_day = $date_time;
             $first_day = CalendarUtils::get_first_day_of_week($date_time);
             $last_day = $first_day->get("+6 days");
             for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                 switch ($dateFormat['date'][$i]) {
                     case "Y":
                         $str .= " " . $first_day->year;
                         break;
                     case "m":
                         $str .= " " . $first_day->get_month_name();
                         break;
                     case "d":
                         $str .= " " . $first_day->get_day();
                         break;
                 }
             }
             $str .= " - ";
             for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                 switch ($dateFormat['date'][$i]) {
                     case "Y":
                         $str .= " " . $last_day->year;
                         break;
                     case "m":
                         $str .= " " . $last_day->get_month_name();
                         break;
                     case "d":
                         $str .= " " . $last_day->get_day();
                         break;
                 }
             }
         } else {
             if ($view == 'agendaDay') {
                 $str .= $date_time->get_day_of_week() . " ";
                 for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                     switch ($dateFormat['date'][$i]) {
                         case "Y":
                             $str .= " " . $date_time->year;
                             break;
                         case "m":
                             $str .= " " . $date_time->get_month_name();
                             break;
                         case "d":
                             $str .= " " . $date_time->get_day();
                             break;
                     }
                 }
             } else {
                 if ($view == 'mobile') {
                     $str .= $date_time->get_day_of_week() . " ";
                     for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                         switch ($dateFormat['date'][$i]) {
                             case "Y":
                                 $str .= " " . $date_time->year;
                                 break;
                             case "m":
                                 $str .= " " . $date_time->get_month_name();
                                 break;
                             case "d":
                                 $str .= " " . $date_time->get_day();
                                 break;
                         }
                     }
                 } else {
                     if ($view == 'year') {
                         $str .= $date_time->year;
                     } else {
                         //could be a custom view.
                         $first_day = $date_time;
                         $first_day = CalendarUtils::get_first_day_of_week($date_time);
                         $last_day = $first_day->get("+6 days");
                         for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                             switch ($dateFormat['date'][$i]) {
                                 case "Y":
                                     $str .= " " . $first_day->year;
                                     break;
                                 case "m":
                                     $str .= " " . $first_day->get_month_name();
                                     break;
                                 case "d":
                                     $str .= " " . $first_day->get_day();
                                     break;
                             }
                         }
                         $str .= " - ";
                         for ($i = 0; $i < strlen($dateFormat['date']); $i++) {
                             switch ($dateFormat['date'][$i]) {
                                 case "Y":
                                     $str .= " " . $last_day->year;
                                     break;
                                 case "m":
                                     $str .= " " . $last_day->get_month_name();
                                     break;
                                 case "d":
                                     $str .= " " . $last_day->get_day();
                                     break;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $str;
 }
示例#16
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $time_arr array of datetimes
  * @return array
  */
 static function save_repeat_activities(SugarBean $bean, $time_arr)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     global $db;
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $users_rel_arr[] = $ro['user_id'];
     }
     $qu_users = "\n\t\t\t\tINSERT INTO {$bean->rel_users_table}\n\t\t\t\t(id,user_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $users_filled = false;
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu_contacts = "\n\t\t\t\tINSERT INTO {$bean->rel_contacts_table}\n\t\t\t\t(id,contact_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $contacts_filled = false;
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_leads = "\n\t\t\t\tINSERT INTO {$bean->rel_leads_table}\n\t\t\t\t(id,lead_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $leads_filled = false;
     $arr = array();
     $i = 0;
     foreach ($time_arr as $date_start) {
         $clone = $bean;
         // we don't use clone keyword cause not necessary
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 if ($users_filled) {
                     $qu_users .= "," . PHP_EOL;
                 }
                 $qu_users .= "('" . create_guid() . "','{$user_id}','{$clone->id}','{$date_modified}')";
                 $users_filled = true;
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 if ($contacts_filled) {
                     $qu_contacts .= "," . PHP_EOL;
                 }
                 $qu_contacts .= "('" . create_guid() . "','{$contact_id}','{$clone->id}','{$date_modified}')";
                 $contacts_filled = true;
             }
             foreach ($leads_rel_arr as $lead_id) {
                 if ($leads_filled) {
                     $qu_leads .= "," . PHP_EOL;
                 }
                 $qu_leads .= "('" . create_guid() . "','{$lead_id}','{$clone->id}','{$date_modified}')";
                 $leads_filled = true;
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     if ($users_filled) {
         $db->query($qu_users);
     }
     if ($contacts_filled) {
         $db->query($qu_contacts);
     }
     if ($leads_filled) {
         $db->query($qu_leads);
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
示例#17
0
    public function mark_deleted($id)
    {
        require_once("modules/Calendar/CalendarUtils.php");
        CalendarUtils::correctRecurrences($this, $id);

        parent::mark_deleted($id);
    }
 function display()
 {
     require_once "modules/Calendar/CalendarUtils.php";
     $field_list = CalendarUtils::get_fields();
     global $beanFiles, $beanList;
     $module = $_REQUEST['current_module'];
     require_once $beanFiles[$beanList[$module]];
     $bean = new $beanList[$module]();
     $type = strtolower($beanList[$module]);
     $table_name = $bean->table_name;
     if (!empty($_REQUEST['record'])) {
         $bean->retrieve($_REQUEST['record']);
     }
     if (!$bean->ACLAccess('Save')) {
         $json_arr = array('success' => 'no');
         echo json_encode($json_arr);
         die;
     }
     require_once 'include/formbase.php';
     $bean = populateFromPost("", $bean);
     if (!$_REQUEST['reminder_checked']) {
         $bean->reminder_time = -1;
     }
     if (empty($_REQUEST['record']) && strpos($_POST['user_invitees'], $bean->assigned_user_id) === false) {
         $_POST['user_invitees'] .= "," . $bean->assigned_user_id;
     }
     // fill invites and save the entry
     $this->save_activity($bean);
     if ($r_id = $bean->id) {
         $u = new User();
         $u->retrieve($bean->assigned_user_id);
         $arr_rec = array();
         $bean->retrieve($r_id);
         if (isset($bean->parent_name)) {
             $bean->parent_name = $_REQUEST['parent_name'];
         }
         $bean->fill_in_additional_parent_fields();
         global $timedate;
         $date_field = "date_start";
         if ($_REQUEST['current_module'] == "Tasks") {
             $date_field = "date_due";
         }
         $timestamp = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $bean->{$date_field}, new DateTimeZone('UTC'))->format('U');
         if ($_REQUEST['current_module'] == 'Calls') {
             $users = $bean->get_call_users();
         }
         if ($_REQUEST['current_module'] == 'Meetings') {
             $users = $bean->get_meeting_users();
         }
         $user_ids = array();
         foreach ($users as $u) {
             $user_ids[] = $u->id;
         }
         $field_arr = array();
         foreach ($field_list[$_REQUEST['current_module']] as $field) {
             $field_arr[$field] = $bean->{$field};
             if ($bean->field_defs[$field]['type'] == 'text') {
                 $t = $field_arr[$field];
                 if (strlen($t) > 300) {
                     $t = substr($t, 0, 300);
                     $t .= "...";
                 }
                 $t = str_replace("\r\n", "<br>", $t);
                 $t = str_replace("\r", "<br>", $t);
                 $t = str_replace("\n", "<br>", $t);
                 $t = html_entity_decode($t, ENT_QUOTES);
                 $field_arr[$field] = $t;
             }
         }
         $json_arr = array('success' => 'yes', 'type' => $type, 'module_name' => $bean->module_dir, 'user_id' => $GLOBALS['current_user']->id, 'detail' => 1, 'edit' => 1, 'record_name' => html_entity_decode($bean->name, ENT_QUOTES), 'record' => $bean->id, 'users' => $user_ids);
         $json_arr = array_merge($json_arr, $field_arr);
         $json_arr = array_merge($json_arr, CalendarUtils::get_time_data($bean));
     } else {
         $json_arr = array('success' => 'no');
     }
     ob_clean();
     echo json_encode($json_arr);
 }