function findByExtCalUserIdValue($user)
 {
     return ExternalCalendars::findOne(array('conditions' => array('`ext_cal_user_id` = ' . $user . ' AND `calendar_feng` = 1')));
 }
 function delete_calendar()
 {
     ajx_current("empty");
     if (!array_var($_POST, 'original_calendar_id')) {
         flash_error(lang('must enter a calendar name'));
         ajx_current("empty");
         return;
     }
     $original_calendar_id = array_var($_POST, 'original_calendar_id');
     $users = ExternalCalendarUsers::findByContactId();
     $calendar = ExternalCalendars::findOne(array('conditions' => array("original_calendar_id=? AND ext_cal_user_id=?", $original_calendar_id, $users->getId())));
     $events = ProjectEvents::findByExtCalId($calendar->getId());
     if ($calendar) {
         if ($calendar->delete()) {
             if ($events) {
                 foreach ($events as $event) {
                     $event->delete();
                 }
             }
             flash_success(lang('success delete calendar'));
             ajx_current("reload");
         }
     }
 }