function add_timespan()
 {
     $object_id = get_id('object_id');
     $object = Objects::findObject($object_id);
     if (!$object instanceof ContentDataObject || !$object->canAddTimeslot(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $timeslot_data = array_var($_POST, 'timeslot');
     $hours = array_var($timeslot_data, 'hours');
     $minutes = array_var($timeslot_data, 'minutes');
     if (strpos($hours, ',') && !strpos($hours, '.')) {
         $hours = str_replace(',', '.', $hours);
     }
     if ($minutes) {
         $min = str_replace('.', '', $minutes / 6);
         $hours = $hours + ("0." . $min);
     }
     $timeslot = new Timeslot();
     $dt = DateTimeValueLib::now();
     $dt2 = DateTimeValueLib::now();
     $timeslot->setEndTime($dt);
     $dt2 = $dt2->add('h', -$hours);
     $timeslot->setStartTime($dt2);
     $timeslot->setDescription(array_var($timeslot_data, 'description'));
     $timeslot->setContactId(array_var($timeslot_data, 'contact_id', logged_user()->getId()));
     $timeslot->setRelObjectId($object_id);
     $billing_category_id = logged_user()->getDefaultBillingId();
     $bc = BillingCategories::findById($billing_category_id);
     if ($bc instanceof BillingCategory) {
         $timeslot->setBillingId($billing_category_id);
         $hourly_billing = $bc->getDefaultValue();
         $timeslot->setHourlyBilling($hourly_billing);
         $timeslot->setFixedBilling($hourly_billing * $hoursToAdd);
         $timeslot->setIsFixedBilling(false);
     }
     try {
         DB::beginWork();
         $timeslot->save();
         /*	dont add timeslots to members, members are taken from the related object
         			$object_controller = new ObjectController();
         			$object_controller->add_to_members($timeslot, $object->getMemberIds());
         		*/
         ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_OPEN);
         $task = ProjectTasks::findById($object_id);
         if ($task->getTimeEstimate() > 0) {
             $timeslots = $task->getTimeslots();
             if (count($timeslots) == 1) {
                 $task->setPercentCompleted(0);
             }
             $timeslot_percent = round($hours * 100 / ($task->getTimeEstimate() / 60));
             $total_percentComplete = $timeslot_percent + $task->getPercentCompleted();
             if ($total_percentComplete < 0) {
                 $total_percentComplete = 0;
             }
             $task->setPercentCompleted($total_percentComplete);
             $task->save();
             $this->notifier_work_estimate($task);
         }
         DB::commit();
         flash_success(lang('success create timeslot'));
         ajx_current("reload");
     } catch (Exception $e) {
         DB::rollback();
         ajx_current("empty");
         flash_error($e->getMessage());
     }
 }
 function addTimeslot(Contact $user)
 {
     if ($this->hasOpenTimeslots($user)) {
         throw new Error("Cannot add timeslot: user already has an open timeslot");
     }
     $timeslot = new Timeslot();
     $dt = DateTimeValueLib::now();
     $timeslot->setStartTime($dt);
     $timeslot->setContactId($user->getId());
     $timeslot->setRelObjectId($this->getObjectId());
     $timeslot->save();
     $object_controller = new ObjectController();
     $object_controller->add_to_members($timeslot, $this->getMemberIds());
 }