Example #1
0
 public static function add_tracing_notes($dest_rset, $dest_id, $dest_label, $linkto_rset, $linkto_id, $linkto_label)
 {
     $after = __('Follow-up after') . ': ';
     $follow = __('Follow-up') . ': ';
     switch ($dest_rset) {
         case 'phonecall':
             $fwd_note_path = 'phonecall/' . $dest_id;
             $bck_note = $after . '[phone=' . $dest_id . ']' . $dest_label . '[/phone]';
             break;
         case 'meeting':
             $fwd_note_path = 'crm_meeting/' . $dest_id;
             $bck_note = $after . '[meeting=' . $dest_id . ']' . $dest_label . '[/meeting]';
             break;
         case 'task':
             $fwd_note_path = 'task/' . $dest_id;
             $bck_note = $after . '[task=' . $dest_id . ']' . $dest_label . '[/task]';
             break;
     }
     switch ($linkto_rset) {
         case 'phonecall':
             $bck_note_path = 'phonecall/' . $linkto_id;
             $fwd_note = $follow . '[phone=' . $linkto_id . ']' . $linkto_label . '[/phone]';
             break;
         case 'meeting':
             $bck_note_path = 'crm_meeting/' . $linkto_id;
             $fwd_note = $follow . '[meeting=' . $linkto_id . ']' . $linkto_label . '[/meeting]';
             break;
         case 'task':
             $bck_note_path = 'task/' . $linkto_id;
             $fwd_note = $follow . '[task=' . $linkto_id . ']' . $linkto_label . '[/task]';
             break;
     }
     Utils_AttachmentCommon::add($fwd_note_path, 0, Acl::get_user(), $fwd_note);
     Utils_AttachmentCommon::add($bck_note_path, 0, Acl::get_user(), $bck_note);
 }
Example #2
0
	public function uninstall() {
		Utils_RecordBrowserCommon::delete_addon('company', 'Tests/Bugtrack', 'company_bugtrack_addon');
		Utils_AttachmentCommon::delete_addon('bugtrack');
		Utils_RecordBrowserCommon::uninstall_recordset('bugtrack');
		Utils_CommonDataCommon::remove('Bugtrack_Status');
		return true;
	}
Example #3
0
 public function uninstall()
 {
     CRM_CalendarCommon::delete_event_handler('Tasks');
     CRM_RoundcubeCommon::delete_addon('task');
     Utils_AttachmentCommon::delete_addon('task');
     Base_ThemeCommon::uninstall_default_theme(CRM_TasksInstall::module_name());
     Utils_RecordBrowserCommon::unregister_processing_callback('task', array('CRM_TasksCommon', 'submit_task'));
     Utils_RecordBrowserCommon::uninstall_recordset('task');
     return true;
 }
Example #4
0
 public function uninstall()
 {
     CRM_CalendarCommon::delete_event_handler('Phonecalls');
     CRM_RoundcubeCommon::delete_addon('phonecall');
     Base_ThemeCommon::uninstall_default_theme(CRM_PhoneCallInstall::module_name());
     Utils_AttachmentCommon::delete_addon('phonecall');
     Utils_AttachmentCommon::persistent_mass_delete('phonecall/');
     Utils_RecordBrowserCommon::unregister_processing_callback('phonecall', array('CRM_PhoneCallCommon', 'submit_phonecall'));
     Utils_RecordBrowserCommon::uninstall_recordset('phonecall');
     return true;
 }
Example #5
0
 public function uninstall()
 {
     Utils_AttachmentCommon::delete_addon('crm_meeting');
     Utils_RecordBrowserCommon::delete_addon('crm_meeting', CRM_MeetingInstall::module_name(), 'messanger_addon');
     CRM_RoundcubeCommon::delete_addon('crm_meeting');
     CRM_CalendarCommon::delete_event_handler('Meetings');
     Base_ThemeCommon::uninstall_default_theme(CRM_MeetingInstall::module_name());
     Utils_RecordBrowserCommon::uninstall_recordset('crm_meeting');
     Utils_RecordBrowserCommon::unregister_processing_callback('crm_meeting', array('CRM_MeetingCommon', 'submit_meeting'));
     return true;
 }
Example #6
0
 public function uninstall()
 {
     Base_ThemeCommon::uninstall_default_theme($this->get_type());
     Utils_CommonDataCommon::remove('crm_assets_category');
     Utils_CommonDataCommon::remove('crm_assets_monitor_type');
     Utils_CommonDataCommon::remove('crm_assets_printer_type');
     Utils_RecordBrowserCommon::delete_addon('company', 'CRM/Assets', 'assets_addon');
     Utils_AttachmentCommon::delete_addon('crm_assets');
     Utils_AttachmentCommon::persistent_mass_delete('crm_assets');
     Utils_RecordBrowserCommon::uninstall_recordset('crm_assets');
     Utils_RecordBrowserCommon::unregister_processing_callback('crm_assets', array('CRM_AssetsCommon', 'process_request'));
     return true;
 }
Example #7
0
 public static function crm_event_get($id, $day = null)
 {
     if (!is_array($id)) {
         $id = explode('_', $id);
         if (isset($id[1]) && $day === null) {
             $day = $id[1];
         }
         $id = reset($id);
         $r = Utils_RecordBrowserCommon::get_record('crm_meeting', $id);
     } else {
         $r = $id;
         $id = $r['id'];
     }
     $r = Utils_RecordBrowserCommon::filter_record_by_access('crm_meeting', $r);
     if ($r === false) {
         return null;
     }
     $next = array('type' => __('Meeting'));
     //		if ($r['duration']!=-1) {
     //			$r['date'] = Base_RegionalSettingsCommon::time2reg($r['date'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false);
     //			$r['recurrence_end'] = Base_RegionalSettingsCommon::time2reg($r['recurrence_end'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false);
     //		}
     if ($day === null) {
         $day = $r['date'];
         $iday = strtotime($day);
         $next['id'] = $r['id'];
     } else {
         $iday = strtotime($day);
         if ($day < $r['date']) {
             return null;
         }
         if ($r['recurrence_end'] && $day > $r['recurrence_end']) {
             return null;
         }
         if ($r['recurrence_type'] <= 7 && $r['recurrence_type'] > 0) {
             $diff = round(($iday - strtotime($r['date'])) / (3600 * 24));
             if ($diff < 0 || $diff % $r['recurrence_type'] != 0) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 8) {
             if (isset($r['recurrence_hash'][date('N', $iday) - 1]) && !$r['recurrence_hash'][date('N', $iday) - 1]) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 9) {
             $diff = round(($iday - strtotime($r['date'])) / (3600 * 24));
             if ($diff < 0 || $diff % 14 != 0) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 10) {
             $numdays = date('t', $iday);
             $cday = date('d', $iday);
             $tday = date('d', strtotime($r['date']));
             if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 11) {
             $cmonth = date('m', $iday);
             $tmonth = date('m', strtotime($r['date']));
             if ($cmonth != $tmonth) {
                 return null;
             }
             $numdays = date('t', $iday);
             $cday = date('d', $iday);
             $tday = date('d', strtotime($r['date']));
             if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) {
                 return null;
             }
         }
         $next['id'] = $r['id'];
     }
     if ($r['recurrence_type'] > 0) {
         $next['id'] = $r['id'] . '_' . $day;
     }
     $base_unix_time = strtotime(date('1970-01-01 00:00:00'));
     //		$next['start'] = Base_RegionalSettingsCommon::reg2time(Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])), true, false, true, false));
     //		$next['end'] = Base_RegionalSettingsCommon::reg2time(date('Y-m-d',$iday).' '.Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])+$r['duration']), true, false, true, false));
     $next['start'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time']));
     $next['end'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time']) + $r['duration']);
     $next['start'] = strtotime($next['start']);
     $next['end'] = strtotime($next['end']);
     if ($r['duration'] == -1) {
         $next['timeless'] = $day;
     }
     $next['duration'] = intval($r['duration']);
     $next['title'] = (string) $r['title'];
     $next['description'] = (string) $r['description'];
     $next['color'] = 'gray';
     if ($r['status'] == 0 || $r['status'] == 1) {
         switch ($r['priority']) {
             case 0:
                 $next['color'] = 'green';
                 break;
             case 1:
                 $next['color'] = 'yellow';
                 break;
             case 2:
                 $next['color'] = 'red';
                 break;
         }
     }
     if ($r['status'] == 2) {
         $next['color'] = 'blue';
     }
     if ($r['status'] == 3) {
         $next['color'] = 'gray';
     }
     if ($r['recurrence_type']) {
         $next['title'] = '<img src="' . Base_ThemeCommon::get_template_file('CRM_Calendar_Event', 'recurrence.png') . '" border=0 hspace=0 vspace=0 align=left>' . $next['title'];
     }
     $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'view', array('day' => $day));
     if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'edit', $r) !== false) {
         $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'edit');
         if ($r['status'] <= 1) {
             $r_new = $r;
             if ($r['status'] == 0) {
                 $r_new['status'] = 1;
             }
             $next['actions'] = array(array('icon' => Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href' => self::get_status_change_leightbox_href($r_new, false, array('id' => 'status'))));
         }
     } else {
         $next['edit_action'] = false;
         $next['move_action'] = false;
     }
     if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'delete', $r) == false) {
         $next['delete_action'] = false;
     }
     $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, $r['duration'] != -1);
     $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, $r['duration'] != -1);
     $end_time = Base_RegionalSettingsCommon::time2reg($next['end'], 2, false, $r['duration'] != -1);
     $inf2 = array(__('Date') => '<b>' . $event_date . '</b>');
     if ($r['duration'] == -1) {
         $inf2 += array(__('Time') => __('Timeless event'));
     } else {
         $inf2 += array(__('Time') => $start_time . ' - ' . $end_time, __('Duration') => Base_RegionalSettingsCommon::seconds_to_words($r['duration']));
     }
     $emps = array();
     foreach ($r['employees'] as $e) {
         $e = CRM_ContactsCommon::contact_format_no_company($e, true);
         $e = str_replace('&nbsp;', ' ', $e);
         if (mb_strlen($e, 'UTF-8') > 33) {
             $e = mb_substr($e, 0, 30, 'UTF-8') . '...';
         }
         $emps[] = $e;
     }
     $next['busy_label'] = $r['employees'];
     $cuss = array();
     foreach ($r['customers'] as $c) {
         $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
         $cuss[] = str_replace('&nbsp;', ' ', $c);
     }
     $inf2 += array(__('Event') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('crm_meeting/' . $r['id']));
     //		$next['employees'] = implode('<br>',$emps);
     //		$next['customers'] = implode('<br>',$cuss);
     $next['employees'] = $r['employees'];
     $next['customers'] = $r['customers'];
     $next['status'] = $r['status'] <= 2 ? 'active' : 'closed';
     $next['custom_tooltip'] = '<center><b>' . __('Meeting') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null);
     return $next;
 }
Example #8
0
                file_put_contents($f_filename, $buffer);
            }
        }
    } else {
        $buffer = file_get_contents($f_filename);
    }
} else {
    $f_filename = $meta['file'];
    if (!file_exists($f_filename)) {
        die('File doesn\'t exists');
    }
    @ini_set('memory_limit', ceil(filesize($f_filename) * 2 / 1024 / 1024 + 64) . 'M');
    $buffer = file_get_contents($f_filename);
}
if ($crypted) {
    $buffer = Utils_AttachmentCommon::decrypt($buffer, $password);
    if ($buffer === false) {
        die('Invalid attachment or password');
    }
}
//mime
file_put_contents($f_filename . 'raw', $buffer);
$mime = get_mime_type($f_filename . 'raw', $original);
unlink($f_filename . 'raw');
$expires = 24 * 60 * 60;
header('Pragma: public');
header('Cache-Control: maxage=' . 24 * 60 * 60);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 24 * 60 * 60) . ' GMT');
header('Content-Type: ' . $mime);
header('Content-Length: ' . strlen($buffer));
header('Content-disposition: ' . $disposition . '; filename="' . $original . '"');
Example #9
0
 * @subpackage attachment
 */
if (!isset($_REQUEST['cid']) || !isset($_REQUEST['file'])) {
    die('Invalid usage');
}
$cid = $_REQUEST['cid'];
$id = $_REQUEST['file'];
if (isset($_REQUEST['description'])) {
    $description = $_REQUEST['description'];
} else {
    $description = '';
}
define('CID', $cid);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Permission denied');
}
$file = DB::GetRow('SELECT uaf.attach_id, uaf.original FROM utils_attachment_file uaf WHERE uaf.id=%d', array($id));
$rec = Utils_RecordBrowserCommon::get_record('utils_attachment', $file['attach_id']);
if (!$rec) {
    die('Invalid attachment.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $rec);
if (!isset($access_fields['note']) || !$access_fields['note']) {
    die('Access forbidden');
}
$t = time() + 3600 * 24 * 7;
print Utils_AttachmentCommon::create_remote($id, $description, $t);
Example #10
0
 public static function crm_event_get($id)
 {
     if (!is_array($id)) {
         $r = Utils_RecordBrowserCommon::get_record('task', $id);
     } else {
         $r = $id;
         $id = $r['id'];
     }
     $r = Utils_RecordBrowserCommon::filter_record_by_access('task', $r);
     if (!$r) {
         return null;
     }
     $next = array('type' => __('Task'));
     $day = $r['deadline'];
     $iday = strtotime($day);
     $next['id'] = $r['id'];
     $base_unix_time = strtotime(date('1970-01-01 00:00:00'));
     $next['start'] = $iday;
     $next['timeless'] = $day;
     $next['duration'] = -1;
     $next['title'] = (string) $r['title'];
     $next['description'] = (string) $r['description'];
     $next['color'] = 'gray';
     if ($r['status'] == 0 || $r['status'] == 1) {
         switch ($r['priority']) {
             case 0:
                 $next['color'] = 'green';
                 break;
             case 1:
                 $next['color'] = 'yellow';
                 break;
             case 2:
                 $next['color'] = 'red';
                 break;
         }
     }
     if ($r['status'] == 2) {
         $next['color'] = 'blue';
     }
     if ($r['status'] == 3) {
         $next['color'] = 'gray';
     }
     $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'view');
     if (Utils_RecordBrowserCommon::get_access('task', 'edit', $r) !== false) {
         $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'edit');
     } else {
         $next['edit_action'] = false;
         $next['move_action'] = false;
     }
     if (Utils_RecordBrowserCommon::get_access('task', 'delete', $r) == false) {
         $next['delete_action'] = false;
     }
     /*		$r_new = $r;
     		if ($r['status']==0) $r_new['status'] = 1;
     		if ($r['status']<=1) $next['actions'] = array(
     			array('icon'=>Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href'=>self::get_status_change_leightbox_href($r_new, false, array('id'=>'status')))
     		);*/
     $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, false);
     $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, false);
     $inf2 = array(__('Date') => '<b>' . $event_date . '</b>');
     $emps = array();
     foreach ($r['employees'] as $e) {
         $e = CRM_ContactsCommon::contact_format_no_company($e, true);
         $e = str_replace('&nbsp;', ' ', $e);
         if (mb_strlen($e, 'UTF-8') > 33) {
             $e = mb_substr($e, 0, 30, 'UTF-8') . '...';
         }
         $emps[] = $e;
     }
     $next['busy_label'] = $r['employees'];
     $cuss = array();
     foreach ($r['customers'] as $c) {
         $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
         $cuss[] = str_replace('&nbsp;', ' ', $c);
     }
     $inf2 += array(__('Task') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('task/' . $r['id']));
     $next['employees'] = $r['employees'];
     $next['customers'] = $r['customers'];
     $next['status'] = $r['status'] <= 2 ? 'active' : 'closed';
     $next['custom_tooltip'] = '<center><b>' . __('Task') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null);
     return $next;
 }
Example #11
0
if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_pages_data', 'Premium/Warehouse/eCommerce', 'attachment_page_addon')) {
    Utils_AttachmentCommon::new_addon('premium_ecommerce_pages_data');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_pages_data', 'Premium/Warehouse/eCommerce', 'attachment_page_desc_addon')) {
    Utils_AttachmentCommon::new_addon('premium_ecommerce_pages_data');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_products', 'Premium/Warehouse/eCommerce', 'attachment_product_addon')) {
    Utils_AttachmentCommon::new_addon('premium_ecommerce_products');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_descriptions', 'Premium/Warehouse/eCommerce', 'attachment_product_desc_addon')) {
    Utils_AttachmentCommon::new_addon('premium_ecommerce_descriptions');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_items', 'Premium/Warehouse/Items', 'attachment_addon')) {
    Utils_AttachmentCommon::new_addon('premium_warehouse_items');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_items_orders', 'Premium/Warehouse/Items/Orders', 'attachment_addon')) {
    Utils_AttachmentCommon::new_addon('premium_warehouse_items_orders');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse', 'Premium/Warehouse', 'attachment_addon')) {
    Utils_AttachmentCommon::new_addon('premium_warehouse');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_distributor', 'Premium/Warehouse/Wholesale', 'attachment_addon')) {
    Utils_AttachmentCommon::new_addon('premium_warehouse_distributor');
}
if (Utils_RecordBrowserCommon::delete_addon('bugtrack', 'Tests/Bugtrack', 'bugtrack_attachment_addon')) {
    Utils_AttachmentCommon::new_addon('bugtrack');
}
if (Utils_RecordBrowserCommon::delete_addon('premium_schoolregister_lesson', 'Premium/SchoolRegister', 'lesson_notes_addon')) {
    Utils_AttachmentCommon::new_addon('premium_schoolregister_lesson');
    DB::Execute('UPDATE utils_attachment_link SET local=' . DB::Concat(DB::qstr('premium_schoolregister_lesson/'), 'local') . ' WHERE local NOT LIKE ' . DB::Concat(DB::qstr('%'), DB::qstr('/'), DB::qstr('%')));
}
Example #12
0
 public static function mail_file($f, $d, $file_id)
 {
     $t = time() + 3600 * 24 * 7;
     $url = Utils_AttachmentCommon::create_remote($file_id, 'mail', $t);
     $x = ModuleManager::get_instance('/Base_Box|0');
     $x->push_main('CRM_Roundcube', 'new_mail', array('', __('File attachment, expires on: %s', array(Base_RegionalSettingsCommon::time2reg($t))), "<br /><br />" . $url));
 }
Example #13
0
 public static function submit_attachment($values, $mode)
 {
     static $new_values, $old_password;
     switch ($mode) {
         case 'browse':
             if (isset($values['id']) && isset($values['crypted']) && $values['crypted'] == false) {
                 // store to mark as read. Do not mark it here, because
                 // we won't get red eye in the table view
                 self::$mark_as_read[] = $values['id'];
             }
             return $values;
         case 'index':
             if ($values['crypted']) {
                 unset($values['note']);
             }
             return $values;
         case 'adding':
             $values['edited_on'] = time();
             return $values;
         case 'add':
         case 'edit':
             if (isset($values['__date'])) {
                 $values['edited_on'] = $values['__date'];
             } else {
                 $values['edited_on'] = time();
             }
             $crypted = 0;
             $old_pass = $mode == 'edit' && isset($_SESSION['client']['cp' . $values['id']]) ? $_SESSION['client']['cp' . $values['id']] : ($mode == 'add' && isset($values['clone_id']) && isset($_SESSION['client']['cp' . $values['clone_id']]) ? $_SESSION['client']['cp' . $values['clone_id']] : '');
             if (is_array($values['crypted']) && isset($values['crypted']['crypted']) && $values['crypted']['crypted'] || !is_array($values['crypted']) && $values['crypted']) {
                 if (is_array($values['crypted']) && isset($values['crypted']['note_password'])) {
                     if ($values['crypted']['note_password'] == '*@#old@#*') {
                         $values['crypted']['note_password'] = $old_pass;
                     }
                 }
                 $crypted = 1;
             }
             if (is_array($values['crypted']) && isset($values['crypted']['note_password']) && $mode == 'edit' && $old_pass != $values['crypted']['note_password']) {
                 //reencrypt old revisions
                 $old_notes = DB::GetAssoc('SELECT hd.edit_id,hd.old_value FROM utils_attachment_edit_history h INNER JOIN utils_attachment_edit_history_data hd ON h.id=hd.edit_id WHERE h.utils_attachment_id=%d AND hd.field="note"', array($values['id']));
                 foreach ($old_notes as $old_id => $old_note) {
                     if ($old_pass !== '') {
                         $old_note = Utils_AttachmentCommon::decrypt($old_note, $old_pass);
                     }
                     if ($old_note === false) {
                         continue;
                     }
                     if ($crypted && $values['crypted']['note_password']) {
                         $old_note = Utils_AttachmentCommon::encrypt($old_note, $values['crypted']['note_password']);
                     }
                     if ($old_note === false) {
                         continue;
                     }
                     DB::Execute('UPDATE utils_attachment_edit_history_data SET old_value=%s WHERE edit_id=%d AND field="note"', array($old_note, $old_id));
                 }
                 //file reencryption
                 $old_files = DB::GetAssoc('SELECT uaf.id as id, uaf.filestorage_id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d', array($values['id']));
                 foreach ($old_files as $id => $fsid) {
                     try {
                         $meta = Utils_FileStorageCommon::meta($fsid);
                     } catch (Exception $e) {
                         continue;
                     }
                     $filename = $meta['file'];
                     $content = @file_get_contents($filename);
                     if ($content === false) {
                         continue;
                     }
                     if ($old_pass !== '') {
                         $content = Utils_AttachmentCommon::decrypt($content, $old_pass);
                     }
                     if ($content === false) {
                         continue;
                     }
                     if ($crypted && $values['crypted']['note_password']) {
                         $content = Utils_AttachmentCommon::encrypt($content, $values['crypted']['note_password']);
                     }
                     if ($content === false) {
                         continue;
                     }
                     $fsid = Utils_FileStorageCommon::write_content($meta['filename'], $content);
                     DB::Execute('UPDATE utils_attachment_file SET filestorage_id=%d WHERE id=%d', array($fsid, $id));
                     Utils_FileStorageCommon::update_link('attachment_file/' . $id, $fsid);
                 }
             }
             if ($crypted) {
                 if (is_array($values['crypted']) && isset($values['crypted']['note_password'])) {
                     $values['note'] = Utils_AttachmentCommon::encrypt($values['note'], $values['crypted']['note_password']);
                     $values['note_password'] = $values['crypted']['note_password'];
                 }
                 $values['crypted'] = 1;
             } else {
                 $values['crypted'] = 0;
             }
             $new_values = $values;
             break;
         case 'cloning':
             $values['clone_id'] = $values['id'];
             break;
         case 'added':
             if (isset($values['local'])) {
                 DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)', array($values['id'], $values['local'], $values['func'], $values['args']));
             }
             $new_values = $values;
             break;
         case 'edit_changes':
             if (isset($values['note']) && isset($values['crypted']) && $new_values['crypted'] != $values['crypted']) {
                 if ($new_values['crypted'] && isset($new_values['note_password'])) {
                     $values['note'] = Utils_AttachmentCommon::encrypt($values['note'], $new_values['note_password']);
                 } elseif (!$new_values['crypted'] && isset($_SESSION['client']['cp' . $new_values['id']])) {
                     $values['note'] = Utils_AttachmentCommon::decrypt($values['note'], $_SESSION['client']['cp' . $new_values['id']]);
                     unset($_SESSION['client']['cp' . $new_values['id']]);
                 }
             } elseif (isset($new_values['note_password']) && isset($old_password) && $new_values['note_password'] != $old_password) {
                 $values['note'] = Utils_AttachmentCommon::decrypt($values['note'], $old_password);
                 $values['note'] = Utils_AttachmentCommon::encrypt($values['note'], $new_values['note_password']);
             }
             unset($values['edited_on']);
             break;
         case 'view':
             $ret = self::get_access($values['id']);
             if (!$ret) {
                 print __('Access denied');
             }
             return $ret;
         case 'display':
             if (DB::GetOne('SELECT 1 FROM utils_attachment_file WHERE attach_id=%d', array($values['id']))) {
                 $ret = array();
                 $ret['new'] = array();
                 $ret['new']['crm_filter'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('File history')) . ' ' . Module::create_href(array('file_history' => 1)) . '>F</a>';
                 if (isset($_REQUEST['file_history']) && (!$values['crypted'] || isset($_SESSION['client']['cp' . $values['id']]))) {
                     Base_BoxCommon::push_module('Utils_Attachment', 'file_history', array($values));
                 }
                 //    CRM_FiltersCommon::set_profile('c'.$values['id']);
                 return $ret;
             }
             break;
         case 'delete':
             if ($values['crypted'] && !isset($_SESSION['client']['cp' . $values['id']])) {
                 Epesi::alert(__('Cannot delete encrypted note'));
                 return false;
             }
             $count_locals = DB::GetOne('SELECT count(DISTINCT local) FROM utils_attachment_local WHERE attachment=%d', array($values['id']));
             if ($count_locals > 1) {
                 $is_local = false;
                 if (isset($_SESSION['client']['utils_attachment_group'])) {
                     $is_local = DB::GetOne('SELECT 1 FROM utils_attachment_local WHERE attachment=%d AND local=%s', array($values['id'], $_SESSION['client']['utils_attachment_group']));
                 }
                 if ($is_local) {
                     DB::Execute('DELETE FROM utils_attachment_local WHERE attachment=%d AND local=%s', array($values['id'], $_SESSION['client']['utils_attachment_group']));
                     self::new_watchdog_event($_SESSION['client']['utils_attachment_group'], '-', $values['id']);
                 } else {
                     Epesi::alert(__('This note is attached to multiple records - please go to record and delete note there.'));
                 }
                 location(array());
                 return false;
             }
             location(array());
             return true;
     }
     switch ($mode) {
         case 'edit':
         case 'added':
             if (isset($values['note_password'])) {
                 $old_password = isset($_SESSION['client']['cp' . $values['id']]) ? $_SESSION['client']['cp' . $values['id']] : '';
                 $_SESSION['client']['cp' . $values['id']] = $values['note_password'];
             }
             $note_id = $values['id'];
             if (isset($values['delete_files'])) {
                 $deleted_files = array_filter(explode(';', $values['delete_files']));
             } else {
                 $deleted_files = array();
             }
             foreach ($deleted_files as $k => $v) {
                 $deleted_files[$k] = intVal($v);
             }
             if ($deleted_files) {
                 $deleted_files = array_combine($deleted_files, $deleted_files);
             }
             if ($mode == 'added' && isset($values['clone_id'])) {
                 //on cloning
                 $locals = DB::Execute('SELECT local,func,args FROM utils_attachment_local WHERE attachment=%d', array($values['clone_id']));
                 while ($local = $locals->FetchRow()) {
                     DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)', array($note_id, $local['local'], $local['func'], $local['args']));
                 }
                 $clone_files = DB::GetAll('SELECT id,original,created_by,created_on,filestorage_id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($values['clone_id']));
                 foreach ($clone_files as $file) {
                     $fsid = $file['filestorage_id'];
                     $content = Utils_FileStorageCommon::read_content($fsid);
                     if (isset($_SESSION['client']['cp' . $values['clone_id']]) && $_SESSION['client']['cp' . $values['clone_id']]) {
                         $content = Utils_AttachmentCommon::decrypt($content, $_SESSION['client']['cp' . $values['clone_id']]);
                     }
                     if ($values['crypted']) {
                         $content = Utils_AttachmentCommon::encrypt($content, $values['note_password']);
                     }
                     $fsid = Utils_FileStorageCommon::write_content($fsid, $content);
                     DB::Execute('INSERT INTO utils_attachment_file (attach_id,deleted,original,created_by,created_on,filestorage_id) VALUES(%d,0,%s,%d,%T,%d)', array($note_id, $file['original'], $file['created_by'], $file['created_on'], $fsid));
                     Utils_FileStorageCommon::add_link('attachment_file/' . DB::Insert_ID('utils_attachment_file', 'id'), $fsid);
                 }
             }
             $current_files = DB::GetAssoc('SELECT id, id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($note_id));
             $remaining_files = $current_files;
             foreach ($deleted_files as $k => $v) {
                 if (!isset($remaining_files[$v])) {
                     unset($deleted_files[$k]);
                 } else {
                     unset($remaining_files[$v]);
                 }
             }
             foreach ($deleted_files as $v) {
                 DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d', array($v));
             }
             if (isset($values['clipboard_files'])) {
                 $clipboard_files = array_filter(explode(';', $values['clipboard_files']));
                 foreach ($clipboard_files as $cf_id) {
                     $cf = DB::GetOne('SELECT filename FROM utils_attachment_clipboard WHERE id=%d', array($cf_id));
                     if ($values['crypted']) {
                         file_put_contents($cf, Utils_AttachmentCommon::encrypt(file_get_contents($cf), $values['note_password']));
                     }
                     Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), __('clipboard') . '.png', $cf);
                 }
             }
             $files = isset($_SESSION['client']['utils_attachment'][CID]['files']) ? $_SESSION['client']['utils_attachment'][CID]['files'] : array();
             $_SESSION['client']['utils_attachment'][CID]['files'] = array();
             foreach ($files as $f) {
                 $file_path = $f['path'];
                 $file_name = $f['name'];
                 if ($values['crypted']) {
                     file_put_contents($file_path, Utils_AttachmentCommon::encrypt(file_get_contents($file_path), $values['note_password']));
                 }
                 Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), $file_name, $file_path);
             }
             $locals = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d', array($note_id));
             foreach ($locals as $local) {
                 $param = explode('/', $local);
                 if (count($param) == 2 && preg_match('/^[1-9][0-9]*$/', $param[1])) {
                     $subscribers = Utils_WatchdogCommon::get_subscribers($param[0], $param[1]);
                     foreach ($subscribers as $user_id) {
                         Utils_WatchdogCommon::user_subscribe($user_id, 'utils_attachment', $note_id);
                     }
                 }
             }
             break;
     }
     return $values;
 }
Example #14
0
 * Use this module if you want to add attachments to some page.
 * @author Arkadiusz Bisaga <*****@*****.**>
 * @copyright Copyright &copy; 2012, Telaxus LLC
 * @license MIT
 * @version 1.0
 * @package epesi-utils
 * @subpackage attachment
 */
if (!isset($_REQUEST['cid']) || !isset($_REQUEST['data'])) {
    die('Invalid usage');
}
define('CID', $_REQUEST['cid']);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Permission denied');
}
$targetDir = Utils_AttachmentCommon::get_temp_dir();
Utils_AttachmentCommon::cleanup_paste_temp();
DB::Execute('INSERT INTO utils_attachment_clipboard (created_by) VALUES (%d)', array(Acl::get_user()));
$id = DB::Insert_ID('utils_attachment_clipboard', 'id');
$filename = 'clipboard' . '_' . $id;
$f_filename = $targetDir . '/' . $filename;
DB::Execute('UPDATE utils_attachment_clipboard SET filename=%s WHERE id=%d', array($f_filename, $id));
$data = explode(',', $_REQUEST['data']);
if (!isset($data[1])) {
    die('Invalid file');
}
file_put_contents($f_filename, base64_decode($data[1]));
die(json_encode(array('id' => $id, 'name' => __('clipboard') . '.png')));
Example #15
0
 public function display_activities($events, $tasks, $phonecalls)
 {
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), 'activities', 'activities');
     $gb->set_table_columns(array(array('name' => __('Type'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Subject'), 'width' => 20), array('name' => __('Date/Deadline'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Employees'), 'width' => 11), array('name' => __('Customers'), 'width' => 11), array('name' => __('Attachments'), 'width' => 4)));
     $amount = 0;
     if ($this->display['events']) {
         $amount += count($events);
     }
     if ($this->display['tasks']) {
         $amount += count($tasks);
     }
     if ($this->display['phonecalls']) {
         $amount += count($phonecalls);
     }
     $limit = $gb->get_limit($amount);
     for ($i = 0; $i < $limit['offset'] + $limit['numrows'] && $i < $amount; $i++) {
         if ($this->display['events'] && count($events)) {
             $ev = current($events);
         } else {
             $ev = array('start' => -1);
         }
         if ($this->display['tasks'] && count($tasks)) {
             $t = current($tasks);
             if (!$t['deadline']) {
                 $t['deadline'] = 0;
             } else {
                 $t['deadline'] = strtotime($t['deadline']);
             }
         } else {
             $t = array('deadline' => -1);
         }
         if ($this->display['phonecalls'] && count($phonecalls)) {
             $ph = current($phonecalls);
             $ph['date_and_time'] = strtotime($ph['date_and_time']);
         } else {
             $ph = array('date_and_time' => -1);
         }
         $maxt = max($ev['start'], $t['deadline'], $ph['date_and_time']);
         $gb_row = $gb->get_new_row();
         if ($ev['start'] == $maxt) {
             $v = array_shift($events);
             if ($i >= $limit['offset'] && $v) {
                 if (isset($v['view_action'])) {
                     $view_href = $v['view_action'];
                 } else {
                     $view_href = $this->create_callback_href(array($this, 'view_event'), array($v['id']));
                 }
                 $title = '<a ' . $view_href . '>' . $v['title'] . '</a>';
                 if (isset($v['description']) && $v['description'] != '') {
                     $title = '<span ' . Utils_TooltipCommon::open_tag_attrs($v['description'], false) . '>' . $title . '</span>';
                 }
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('crm_meeting', $v['id']));
                 $gb_row->add_data(__('Meeting'), $title, Base_RegionalSettingsCommon::time2reg($v['start'], $v['duration'] == -1 ? false : 2), CRM_ContactsCommon::display_contact(array('employees' => $v['employees']), false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact(array('customers' => $v['customers']), false, array('id' => 'customers', 'param' => ';::')), Utils_AttachmentCommon::count('crm_meeting/' . $v['id']));
             }
         } elseif ($t['deadline'] == $maxt) {
             $v = array_shift($tasks);
             $v = Utils_RecordBrowserCommon::filter_record_by_access('task', $v);
             if ($i >= $limit['offset'] && $v) {
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('task', $v['id']));
                 $gb_row->add_data(__('Task'), CRM_TasksCommon::display_title($v, false), !isset($v['deadline']) || !$v['deadline'] ? __('No deadline') : Base_RegionalSettingsCommon::time2reg($v['deadline'], false, true, false), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact($v, false, array('id' => 'customers')), Utils_AttachmentCommon::count('task/' . $v['id']));
             }
         } else {
             $v = array_shift($phonecalls);
             $v = Utils_RecordBrowserCommon::filter_record_by_access('phonecall', $v);
             if ($i >= $limit['offset'] && $v) {
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('phonecall', $v['id']));
                 $gb_row->add_data(__('Phonecall'), CRM_PhoneCallCommon::display_subject($v), Base_RegionalSettingsCommon::time2reg($v['date_and_time'], 2), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_PhoneCallCommon::display_contact_name($v, false), Utils_AttachmentCommon::count('phonecall/' . $v['id']));
             }
         }
     }
     $this->display_module($gb);
 }
Example #16
0
<?php

if (!isset($_REQUEST['cid']) || !isset($_REQUEST['id']) || !isset($_REQUEST['pass'])) {
    die('Invalid usage');
}
$cid = $_REQUEST['cid'];
$id = $_REQUEST['id'];
$pass = $_REQUEST['pass'];
define('CID', $cid);
define('READ_ONLY_SESSION', false);
require_once '../../../include.php';
ModuleManager::load_modules();
$row = Utils_RecordBrowserCommon::get_record('utils_attachment', $id);
if (!Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $row)) {
    die(json_encode(array('error' => __('Access denied'))));
}
$decoded = Utils_AttachmentCommon::decrypt($row['note'], $pass);
if ($decoded !== false) {
    $_SESSION['client']['cp' . $row['id']] = $pass;
    ob_start();
    $note = Utils_AttachmentCommon::display_note($row, false, null, 'utils_attachment', true);
    $note = ob_get_clean() . $note;
    die(json_encode(array('note' => $note, 'js' => Epesi::get_output())));
}
die(json_encode(array('error' => __('Invalid password'))));
Example #17
0
 public function uninstall()
 {
     Base_AclCommon::remove_clearance_callback(array('CRM_ContactsCommon', 'crm_clearance'));
     Base_ThemeCommon::uninstall_default_theme(CRM_ContactsInstall::module_name());
     Utils_RecordBrowserCommon::unregister_datatype('crm_company');
     Utils_RecordBrowserCommon::unregister_datatype('crm_contact');
     Utils_RecordBrowserCommon::unregister_datatype('crm_company_contact');
     Utils_RecordBrowserCommon::unregister_datatype('email');
     Utils_RecordBrowserCommon::delete_addon('company', CRM_ContactsInstall::module_name(), 'company_addon');
     Utils_AttachmentCommon::delete_addon('company');
     Utils_AttachmentCommon::delete_addon('contact');
     Utils_RecordBrowserCommon::uninstall_recordset('company');
     Utils_RecordBrowserCommon::uninstall_recordset('contact');
     Utils_CommonDataCommon::remove('Contacts_Groups');
     Utils_CommonDataCommon::remove('Companies_Groups');
     Utils_RecordBrowserCommon::unregister_processing_callback('contact', array('CRM_ContactsCommon', 'submit_contact'));
     return true;
 }
Example #18
0
    public static function discard_google_docs($note_id) {
        $edit_url = DB::GetOne('SELECT doc_id FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id));
        DB::Execute('DELETE FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id));
        $g_auth = Utils_AttachmentCommon::get_google_auth();
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $headers = array(
            "Authorization: GoogleLogin auth=" . $g_auth,
            "If-Match: *",
            "GData-Version: 3.0",
        );
        curl_setopt($curl, CURLOPT_URL, $edit_url);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_POST, false);
        $response = curl_exec($curl);
        Base_StatusBarCommon::message(__('Changes discarded'));
    }
Example #19
0
 public function file_history($attachment)
 {
     if ($this->is_back()) {
         $x = ModuleManager::get_instance('/Base_Box|0');
         if (!$x) {
             trigger_error('There is no base box module instance', E_USER_ERROR);
         }
         return $x->pop_main();
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $id = $attachment['id'];
     $tb =& $this->init_module(Utils_TabbedBrowser::module_name());
     $tb->start_tab('File history');
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'hua' . $id);
     $gb->set_inline_display();
     $gb->set_table_columns(array(array('name' => __('Deleted'), 'order' => 'deleted', 'width' => 10), array('name' => __('Date'), 'order' => 'upload_on', 'width' => 25), array('name' => __('Who'), 'order' => 'upload_by', 'width' => 25), array('name' => __('Attachment'), 'order' => 'uaf.original')));
     $gb->set_default_order(array(__('Date') => 'DESC'));
     $ret = $gb->query_order_limit('SELECT uaf.id,uaf.deleted,uaf.filestorage_id,uaf.created_on as upload_on,uaf.created_by as upload_by,uaf.original FROM utils_attachment_file uaf WHERE uaf.attach_id=' . $id, 'SELECT count(*) FROM utils_attachment_file uaf WHERE uaf.attach_id=' . $id);
     while ($row = $ret->FetchRow()) {
         $r = $gb->get_new_row();
         if ($row['deleted']) {
             $r->add_action($this->create_confirm_callback_href(__('Are you sure you want to restore attached file?'), array($this, 'restore_file'), array($row['id'])), 'restore', __('Restore'));
         }
         $view_link = '';
         $lb = array();
         $lb['aid'] = $id;
         $lb['crypted'] = $attachment['crypted'];
         $lb['original'] = $row['original'];
         $lb['id'] = $row['id'];
         $lb['filestorage_id'] = $row['filestorage_id'];
         $file = '<a ' . Utils_AttachmentCommon::get_file_leightbox($lb, $view_link) . '>' . $row['original'] . '</a>';
         $r->add_data($row['deleted'] ? __('Yes') : __('No'), Base_RegionalSettingsCommon::time2reg($row['upload_on']), Base_UserCommon::get_user_label($row['upload_by']), $file);
     }
     $this->display_module($gb);
     $tb->end_tab();
     $tb->start_tab('File access history');
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'hda' . $id);
     $gb->set_inline_display();
     $gb->set_table_columns(array(array('name' => __('Create date'), 'order' => 'created_on', 'width' => 15), array('name' => __('Download date'), 'order' => 'download_on', 'width' => 15), array('name' => __('Who'), 'order' => 'created_by', 'width' => 15), array('name' => __('IP Address'), 'order' => 'ip_address', 'width' => 15), array('name' => __('Host Name'), 'order' => 'host_name', 'width' => 15), array('name' => __('Method description'), 'order' => 'description', 'width' => 20), array('name' => __('Remote'), 'order' => 'remote', 'width' => 10)));
     $gb->set_default_order(array(__('Create date') => 'DESC'));
     $query = 'SELECT uad.created_on,uad.download_on,(SELECT l.login FROM user_login l WHERE uad.created_by=l.id) as created_by,uad.remote,uad.ip_address,uad.host_name,uad.description FROM utils_attachment_download uad INNER JOIN utils_attachment_file uaf ON uaf.id=uad.attach_file_id WHERE uaf.attach_id=' . $id;
     $query_qty = 'SELECT count(*) FROM utils_attachment_download uad INNER JOIN utils_attachment_file uaf ON uaf.id=uad.attach_file_id WHERE uaf.attach_id=' . $id;
     if (Base_AclCommon::check_permission('Attachments - view full download history')) {
         $ret = $gb->query_order_limit($query, $query_qty);
     } else {
         print 'You are allowed to see your own downloads only';
         $who = ' AND uad.created_by=' . Acl::get_user();
         $ret = $gb->query_order_limit($query . $who, $query_qty . $who);
     }
     while ($row = $ret->FetchRow()) {
         $r = $gb->get_new_row();
         $r->add_data(Base_RegionalSettingsCommon::time2reg($row['created_on']), $row['remote'] != 1 ? Base_RegionalSettingsCommon::time2reg($row['download_on']) : '', $row['created_by'], $row['ip_address'], $row['host_name'], $row['description'], $row['remote'] == 0 ? 'no' : 'yes');
     }
     $this->display_module($gb);
     $tb->end_tab();
     $this->display_module($tb);
     $this->caption = 'Note history';
     return true;
 }
Example #20
0
$t = time();
$remote_address = $_SERVER['REMOTE_ADDR'];
$remote_host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
DB::Execute('INSERT INTO utils_attachment_download(attach_file_id,created_by,created_on,download_on,description,ip_address,host_name) VALUES (%d,%d,%T,%T,%s,%s,%s)',array($id,Acl::get_user(),$t,$t,$disposition,$remote_address,$remote_host));
$f_filename = DATA_DIR.'/Utils_Attachment/'.$filename;
if(!file_exists($f_filename))
	die('File doesn\'t exists');
$buffer = file_get_contents($f_filename);
if($crypted) {
    $password = $_SESSION['client']['cp'.$rec['id']];
    $buffer = Utils_AttachmentCommon::decrypt($buffer,$password);
    if($buffer===false) die('Invalid attachment or password');
}
$buffer_size = strlen($buffer);

$g_auth = Utils_AttachmentCommon::get_google_auth();

if ($g_auth) {
	DB::StartTrans();
    $view_row = DB::GetRow('SELECT id, view_link FROM utils_attachment_googledocs WHERE note_id=%d', array($id));
	if (empty($view_row)) {
		$view_doc = null;
		DB::Execute('INSERT INTO utils_attachment_googledocs (view_link, note_id, doc_id) VALUES (%s, %d, %s)', array('', $id, ''));
		$uag_id = DB::Insert_ID('utils_attachment_googledocs','id');
	} else {
		$view_doc = $view_row[1]?$view_row[1]:'';
	}
	DB::CompleteTrans();
	$wait = 15;
	$time = microtime(true);
	if ($view_doc==='' && $wait > 0) {