예제 #1
0
 public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #2
0
파일: view.php 프로젝트: Jtgadbois/Pedadida
		<table>';
		foreach($attachments as $att) {
			if (!array_var($att, 'hide')) {
				$size = $att['size'];//format_filesize(strlen($att["Data"]));
				$fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]);
				if (trim($fName) == "" && strlen($att["FileName"]) > 0) $fName = utf8_encode($att["FileName"]);
				$description .= '<tr><td style="padding-right: 10px">';
				$ext = get_file_extension($fName);
				$fileType = FileTypes::getByExtension($ext);
				if (isset($fileType))
					$icon = $fileType->getIcon();
				else
					$icon = "unknown.png";
				$download_url = get_url('mail', 'download_attachment', array('email_id' => $email->getId(), 'attachment_id' => $c));
				include_once ROOT . "/library/browser/Browser.php";
				if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
					$download_url = "javascript:location.href = '$download_url';";
				}
	      		$description .=	'<img src="' . get_image_url("filetypes/" . $icon) .'"></td>
				<td><a target="_self" href="' . $download_url . '">' . clean($fName) . " ($size)" . '</a></td></tr>';
			}
      		$c++;
		}
		$description .= '</table></div></fieldset></td></tr>';
  } //if
  $description .= '</table></div>';
		if (($email_count = MailContents::countMailsInConversation($email)) > 1) {
			$emails_info = MailContents::getMailsFromConversation($email);
			$conversation_block = '';
			$conversation_block .= '<div id="'.$genid.'conversation" style="margin-bottom:10px;' . 
				(count($emails_info) > 6 ? 'max-height:101px;overflow:auto' : ''  ) . '"><table style="width:100%;">';
 /**
  * Show and process login form
  *
  * @param void
  * @return null
  */
 function login()
 {
     include_once ROOT . "/library/browser/Browser.php";
     if (Browser::instance()->getBrowser() == Browser::BROWSER_IE && Browser::instance()->getVersion() < 7) {
         flash_error(lang("ie browser outdated"));
     }
     $this->addHelper('form');
     if (function_exists('logged_user') && (logged_user() instanceof Contact && logged_user()->isUser())) {
         $ref_controller = null;
         $ref_action = null;
         $ref_params = array();
         foreach ($_GET as $k => $v) {
             if (str_starts_with($k, 'ref_')) {
                 $ref_var_name = trim(substr($k, 4, strlen($k)));
                 switch ($ref_var_name) {
                     case 'c':
                         $ref_controller = $v;
                         break;
                     case 'a':
                         $ref_action = $v;
                         break;
                     default:
                         $ref_params[$ref_var_name] = $v;
                 }
                 // switch
             }
             // if
         }
         // if
         $this->redirectTo($ref_controller, $ref_action, $ref_params);
     }
     // if
     $login_data = array_var($_POST, 'login');
     $localization = array_var($_POST, 'configOptionSelect');
     if (!is_array($login_data)) {
         $login_data = array();
         foreach ($_GET as $k => $v) {
             if (str_starts_with($k, 'ref_')) {
                 $login_data[htmlspecialchars($k)] = htmlspecialchars($v);
             }
         }
         // foreach
     }
     // if
     tpl_assign('login_data', $login_data);
     if (is_array(array_var($_POST, 'login'))) {
         $username = array_var($login_data, 'username');
         $password = array_var($login_data, 'password');
         $remember = array_var($login_data, 'remember') == 'checked';
         if (config_option('block_login_after_x_tries')) {
             $from_time = DateTimeValueLib::now();
             $from_time = $from_time->add('m', -10);
             $sec_logs = AdministrationLogs::getLastLogs(AdministrationLogs::ADM_LOG_CATEGORY_SECURITY, "invalid login", array_var($_SERVER, 'REMOTE_ADDR'), 10, "`created_on` > '" . $from_time->toMySQL() . "'");
             if (is_array($sec_logs) && count($sec_logs) >= 5) {
                 AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
                 tpl_assign('error', new Error(lang('invalid login data')));
                 $this->render();
             }
         }
         if (trim($username) == '') {
             AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
             tpl_assign('error', new Error(lang('username value missing')));
             $this->render();
         }
         // if
         if (trim($password) == '') {
             AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
             tpl_assign('error', new Error(lang('password value missing')));
             $this->render();
         }
         // if
         if (preg_match(EMAIL_FORMAT, $username)) {
             $user = Contacts::getByEmail($username);
         } else {
             $user = Contacts::getByUsername($username);
         }
         if (!($user instanceof Contact && $user->isUser()) || $user->getDisabled()) {
             AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
             tpl_assign('error', new Error(lang('invalid login data')));
             $this->render();
         }
         // if
         $userIsValidPassword = false;
         // If ldap authentication is enabled ldap.config.php will return true.
         $config_ldap_file_path = ROOT . '/config/ldap.config.php';
         $config_ldap_is_set = file_exists($config_ldap_file_path) && (include_once $config_ldap_file_path);
         if ($config_ldap_is_set === true) {
             $userIsValidPassword = $user->isValidPasswordLdap($username, $password, $config_ldap);
         }
         if (!$userIsValidPassword) {
             $userIsValidPassword = $user->isValidPassword($password);
         }
         if (!$userIsValidPassword) {
             AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
             tpl_assign('error', new Error(lang('invalid login data')));
             $this->render();
         }
         // if
         //Start change user language
         if ($localization != 'Default' && self::check_valid_localization($localization)) {
             set_user_config_option('localization', $localization, $user->getId());
         }
         $ref_controller = null;
         $ref_action = null;
         $ref_params = array();
         foreach ($login_data as $k => $v) {
             if (str_starts_with($k, 'ref_')) {
                 $ref_var_name = trim(substr($k, 4, strlen($k)));
                 switch ($ref_var_name) {
                     case 'c':
                         $ref_controller = $v;
                         break;
                     case 'a':
                         $ref_action = $v;
                         break;
                     default:
                         $ref_params[$ref_var_name] = $v;
                 }
                 // switch
             }
             // if
         }
         // if
         if (!count($ref_params)) {
             $ref_params = null;
         }
         if (ContactPasswords::validatePassword($password)) {
             $newest_password = ContactPasswords::getNewestContactPassword($user->getId());
             if (!$newest_password instanceof ContactPassword) {
                 $user_password = new ContactPassword();
                 $user_password->setContactId($user->getId());
                 $user_password->setPasswordDate(DateTimeValueLib::now());
                 $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp()));
                 $user_password->password_temp = $password;
                 $user_password->save();
             } else {
                 if (ContactPasswords::isContactPasswordExpired($user->getId())) {
                     $this->redirectTo('access', 'change_password', array('id' => $user->getId(), 'msg' => 'expired', 'ref_c' => $ref_controller, 'ref_a' => $ref_action, $ref_params));
                 }
             }
         } else {
             $this->redirectTo('access', 'change_password', array('id' => $user->getId(), 'msg' => 'invalid', 'ref_c' => $ref_controller, 'ref_a' => $ref_action, $ref_params));
         }
         try {
             CompanyWebsite::instance()->logUserIn($user, $remember);
             $ip = get_ip_address();
             ApplicationLogs::createLog($user, ApplicationLogs::ACTION_LOGIN, false, false, true, $ip);
         } catch (Exception $e) {
             tpl_assign('error', new Error(lang('invalid login data')));
             $this->render();
         }
         // try
         if ($ref_controller && $ref_action) {
             $this->redirectTo($ref_controller, $ref_action, $ref_params);
         } else {
             $this->redirectTo('access', 'index');
         }
         // if
     }
     // if
 }
예제 #4
0
/**
 * Use content (from file, from database, other source...) and pass it to the browser as a file
 *
 * @param string $content
 * @param string $type MIME type
 * @param string $name File name
 * @param integer $size File size
 * @param boolean $force_download Send Content-Disposition: attachment to force save dialog
 * @return boolean
 */
function download_contents($content, $type, $name, $size, $force_download = false) {
	if(connection_status() != 0) return false; // check connection

	include_once ROOT . "/library/browser/Browser.php";
	if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
		$name = rawurlencode($name);
	}
	
	/*
	if($force_download) {
		header("Cache-Control: public");
	} else {
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");
	} // if
	*/
	if (ob_get_length()) ob_clean();
	header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Content-Type: $type");
	header("Content-Length: " . (string) $size);

	// Prepare disposition
	$disposition = $force_download ? 'attachment' : 'inline';
	header("Content-Disposition: $disposition; filename=\"" . $name . "\"");
	header("Content-Transfer-Encoding: binary");
	header("Cache-Control: maxage=1"); // Age is in seconds.
   	header("Pragma: public");
   	
	print $content;

	return((connection_status() == 0) && !connection_aborted());
} // download_contents
 /**
  * Edit contact picture
  * @TODO: Si es Internet exploer hacerlo como antes
  * @param void
  * @return null
  */
 function edit_picture()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     if (!array_var($_REQUEST, 'new_contact')) {
         $contact = Contacts::findById(get_id());
         if (!$contact instanceof Contact) {
             flash_error(lang('contact dnx'));
             ajx_current("empty");
             return;
         }
         // if
         if (!$contact->canEdit(logged_user())) {
             flash_error(lang('no access permissions'));
             ajx_current("empty");
             return;
         }
         // if
         $redirect_to = array_var($_GET, 'redirect_to');
         if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
             $redirect_to = $contact->getUpdatePictureUrl();
         }
         // if
         tpl_assign('redirect_to', $redirect_to);
         $is_new = false;
     } else {
         $contact = new Contact();
         $is_new = true;
     }
     $picture = array_var($_FILES, 'new_picture');
     tpl_assign('contact', $contact);
     tpl_assign('reload_picture', array_var($_REQUEST, 'reload_picture'));
     tpl_assign('new_contact', array_var($_REQUEST, 'new_contact'));
     if (is_array($picture)) {
         //Env::useLibrary('browser');
         include_once ROOT . "/library/browser/Browser.php";
         if (!array_var($_REQUEST, 'new_contact')) {
             $old_file = $contact->getPicturePath();
             DB::beginWork();
             if (!array_var($_REQUEST, 'is_company')) {
                 if (Browser::instance()->getBrowser() == Browser::BROWSER_IE && intval(Browser::instance()->getVersion()) < 10) {
                     $size = getimagesize($picture['tmp_name']);
                     $w = $size[0] < $size[1] ? $size[0] : $size[1];
                     $image_path = process_uploaded_cropped_picture_file($picture, array('x' => 0, 'y' => 0, 'w' => $w, 'h' => $w));
                 } else {
                     $crop_data = array('x' => array_var($_POST, 'x'), 'y' => array_var($_POST, 'y'), 'w' => array_var($_POST, 'w'), 'h' => array_var($_POST, 'h'));
                     $image_path = process_uploaded_cropped_picture_file($picture, $crop_data);
                 }
             } else {
                 $image_path = $picture['tmp_name'];
             }
             if (!$contact->setPicture($image_path, 'image/png')) {
                 throw new InvalidUploadError($picture);
             }
             DB::commit();
             ApplicationLogs::createLog($contact, ApplicationLogs::ACTION_EDIT);
             if (is_file($old_file)) {
                 @unlink($old_file);
             }
             // if
             flash_success(lang('success edit picture'));
             if (array_var($_REQUEST, 'reload_picture')) {
                 evt_add('reload user picture', array('contact_id' => $contact->getId(), 'url' => $contact->getPictureUrl(), 'el_id' => array_var($_REQUEST, 'reload_picture')));
             }
         } else {
             if (!array_var($_REQUEST, 'is_company')) {
                 if (Browser::instance()->getBrowser() == Browser::BROWSER_IE && intval(Browser::instance()->getVersion()) < 10) {
                     $size = getimagesize($picture['tmp_name']);
                     $w = $size[0] < $size[1] ? $size[0] : $size[1];
                     $image_path = process_uploaded_cropped_picture_file($picture, array('x' => 0, 'y' => 0, 'w' => $w, 'h' => $w));
                 } else {
                     $crop_data = array('x' => array_var($_POST, 'x'), 'y' => array_var($_POST, 'y'), 'w' => array_var($_POST, 'w'), 'h' => array_var($_POST, 'h'));
                     $image_path = process_uploaded_cropped_picture_file($picture, $crop_data);
                 }
             } else {
                 $image_path = $picture['tmp_name'];
             }
             if ($is_new) {
                 $file_id = $contact->setPicture($image_path, 'image/png', null, null, false);
                 $_SESSION['new_contact_picture'] = $file_id;
             } else {
                 if (!$contact->setPicture($image_path, 'image/png')) {
                     throw new InvalidUploadError($picture);
                 }
             }
             if (array_var($_REQUEST, 'reload_picture')) {
                 evt_add('reload user picture', array('contact_id' => $contact->getId(), 'url' => $contact->getPictureUrl(), 'el_id' => array_var($_REQUEST, 'reload_picture'), 'file_id' => $contact->getPictureFile(), 'hf_picture' => array_var($_REQUEST, 'new_contact')));
             }
             flash_success(lang('success edit picture'));
         }
         ajx_current("back");
     }
 }
예제 #6
0
function pdf_convert_and_download($html_filename, $download_filename = null, $orientation = "Portrait")
{
    $html_to_convert = file_get_contents($html_filename);
    if (!$download_filename) {
        $download_filename = gen_id() . '.pdf';
    }
    //generate the pdf
    $pdf_filename = convert_to_pdf($html_to_convert, $orientation, gen_id());
    if ($pdf_filename) {
        include_once ROOT . "/library/browser/Browser.php";
        if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
            evt_add('download_tmp_file', array('file_name' => $pdf_filename, 'file_type' => 'application/pdf'));
        } else {
            download_file(ROOT . "/tmp/" . $pdf_filename, 'application/pdf', $download_filename, true);
        }
    }
}
예제 #7
0
/**
 * Use content (from file, from database, other source...) and pass it to the browser as a file
 *
 * @param string $content
 * @param string $type MIME type
 * @param string $name File name
 * @param integer $size File size
 * @param boolean $force_download Send Content-Disposition: attachment to force save dialog
 * @return boolean
 */
function download_contents($content, $type, $name, $size, $disp_attachment = false, $force_download = true)
{
    if (connection_status() != 0) {
        return false;
    }
    // check connection
    include_once ROOT . "/library/browser/Browser.php";
    if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
        $name = rawurlencode($name);
    }
    if (ob_get_length()) {
        ob_clean();
    }
    header("Content-Type: {$type}");
    header("Content-Length: " . (string) $size);
    // Prepare disposition
    $disposition = $disp_attachment ? 'attachment' : 'inline';
    header("Content-Disposition: {$disposition}; filename=\"" . $name . "\"");
    header("Content-Transfer-Encoding: binary");
    if ($force_download) {
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
        // Age is in seconds.
        header("Cache-Control: post-check=0, pre-check=0");
        header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    } else {
        header("Cache-Control: maxage=2592000");
        // 1 month
        $next = DateTimeValueLib::now();
        // next month
        $next = $next->add('M', 1);
        header("Expires: " . $next->format("D, d M Y H:i:s") . " GMT");
    }
    header("Pragma: public");
    print $content;
    return connection_status() == 0 && !connection_aborted();
}
예제 #8
0
?>
	<![endif]-->
	<!--[if IE 8]>
	<?php 
echo stylesheet_tag("og/ie8.css");
?>
	<![endif]-->
	<?php 
$loading_url = get_image_url("layout/loading.gif");
Hook::fire('change_loading_img', null, $loading_url);
?>
	<?php 
echo meta_tag('content-type', 'text/html; charset=utf-8', true);
// Old Internet Explorer versions does not allow to import more than 32 css files, so we must use the compressed css.
include_once ROOT . "/library/browser/Browser.php";
$is_old_ie = Browser::instance()->getBrowser() == Browser::BROWSER_IE && Browser::instance()->getVersion() < 10;
// By default use compressed css
if (!defined('COMPRESSED_CSS')) {
    define('COMPRESSED_CSS', true);
}
$version = product_version();
if ($is_old_ie || COMPRESSED_CSS) {
    echo stylesheet_tag("ogmin.css");
} else {
    echo stylesheet_tag('website.css');
}
// Include plguin specif stylesheets - include all installed plugins, no matter if they they have not been activated
foreach (Plugins::instance()->getAll() as $p) {
    /* @var $p Plugin */
    $css_file = PLUGIN_PATH . "/" . $p->getSystemName() . "/public/assets/css/" . $p->getSystemName() . ".css";
    if (is_file($css_file)) {