src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/app/include/app_utilities.php

364 lines
9.9 KiB
PHP

<?php
/** \file app_utilities.php
* \brief DI utilities
* \author Bram Lentjes, Core|Vision
* \version 1.0
* \date 03-07-2013
*
* This file contains the utilities file.
*/
/*
* Name : createRandomNumberCode($nmr)
* Parameters : - nmr
* Description : create a random code
*/
function createRandomNumberCode($nmr) {
// $chars = "abcdefghijkmnpqrstuvwxyz";
$nums = "0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i < $nmr) {
$num = rand() % 10;
$tmp = substr($nums, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
/*
* Name : checkSizeUsername($username)
* Parameters : - username
* Description : Check if the username is not to big
*/
function checkSizeUsername($username){
$names;
if(strlen($username ) > USER_NAME_LENGTH){
$names = explode(' ', $username );
// check if firstname is not to big else lastname not to big
if(strlen($names[0]) <= USER_NAME_LENGTH){
$username = $names[0];
}elseif(strlen($names[1]) <= USER_NAME_LENGTH) {
$username = $names[1];
}
}
return $username;
}
/*
* Name : get_file_extension($file_name, &$mimetype)
* Parameters : - file_name
* - mimetype
* Description : Get extenstion of the file
*/
function get_file_extension($file_name, &$mimetype) {
// Get extenstion of the filename
$ext = strtolower(substr(strrchr($file_name,'.'),1));
// Set mimetype
switch($ext){
case 'pdf':
$mimetype = 'application/pdf';
break;
case 'doc':
$mimetype = 'application/msword';
break;
case 'docx':
$mimetype = 'application/msword';
break;
case 'odt':
$mimetype = 'application/vnd.oasis.opendocument.text';
break;
case 'ods':
$mimetype = 'application/vnd.oasis.opendocument.spreadsheet';
break;
case 'xls':
$mimetype = 'application/vnd.ms-excel';
break;
case 'mp3':
$mimetype = 'audio/mpeg';
break;
case 'mp4':
$mimetype = 'video/mp4';
break;
case 'txt':
$mimetype = 'application/msword';
break;
case 'jpg':
$mimetype = 'image/jpeg';
break;
case 'jpeg':
$mimetype = 'image/jpeg';
break;
case 'png':
$mimetype = 'image/png';
break;
case 'gif':
$mimetype = 'image/gif';
break;
case 'csv':
$mimetype ='text/csv';
break;
case 'html':
$mimetype ='text/html';
break;
case 'flv':
$mimetype ='video/x-flv';
break;
case 'mpg':
$mimetype - 'video/mpeg';
break;
case 'avi':
$mimetype - 'video/x-msvideo';
break;
case 'wma':
$mimetype = 'audio/x-ms-wma';
break;
default:
$mimetype = "not supported";
break;
}
return $ext;
}
/*
* Name : delete_characters($name)
* Parameters : - name
* Description : Delete unwanted characters
*/
function delete_characters($name) {
// Characters to delete from the string
$deleted_chars = array("\"","?","*",":", "|", "<", ">"," ","#","&","'");
$new_name = str_replace($deleted_chars, "_", $name);
// delete backslash
return stripslashes($new_name);
}
/*
* Name : cut_name($name)
* Parameters : - name
* Description : Cut name
*/
function cut_name($name, $cut_size=20) {
if(strlen($name) > $cut_size ){
$new_name = substr($name, 0 , $cut_size);
$new_name .= "..";
return $new_name;
}
return $name;
}
/*
* Name : check_project($project_id)
* Parameters : - project_id
* Description : Check if user have the correct project rights
*/
function check_project($project_id){
$project = db_fetch_project($project_id,"",1);
// Check for non-released/released projects
// normal project => planning status must be finished (and non-RS3000)
// rc project => planning and design status must be validated
if (($project['status'] != "afgesloten") && ((($project['type'] == "normaal") &&
($project['pstatus'] == "gereed"))) ||(($project['type'] == "rc") && (($project['pstatus'] == "gevalideerd") &&
($project['ostatus'] == "gevalideerd")))) {
return 1;
}
return 0;
}
/*
* Name : preload_images($path)
* Parameters : - path
* Description : preload the images from the selected images path
*/
function preload_images($path){
GLOBAL $_PAGE_INFO;
// Check if images are loaded already
if(!isset($_SESSION[$_PAGE_INFO['id']]['preload_images'][' ' . $path . ' '])){
// Get all filenames of the images
$file_images = get_all_files("app/html/images/" . $path . "/","");
// Create divs to pre load al images once
foreach($file_images as $file_image){
echo "<div style=\"display:none;background-image:url(" . $file_image . ")\"></div>";
}
$_SESSION[$_PAGE_INFO['id']]['preload_images'][' ' . $path . ' '] = TRUE;
}
}
/*
* Name : place_header($info)
* Parameters : $info[text_header]
* $info[text_login_button]
* $info[id_login_button]
* $info[id_connection_icon]
* Description : place header
*/
function place_header($info){
echo "
<!-- Left header -->
<div class=\"div_left_header\">";
// Check if text_header is not empty. if empty then get text for the header from javascript
if(!empty($info['text_header'])){
echo"
<div class=\"div_left_header_text\">
" . strtoupper($info['text_header']) . "
</div>";
}else{
echo"
<!-- fake onclick to call -->
<input id=\"fakeclick_name\" name=\"fakeclick_name\" type=\"hidden\" onClick=\"getProjectName('project_name');\">
<div id=\"project_name\" class=\"div_left_header_text\">
</div>";
}
echo"
</div>
<!-- Connection type icon -->
<div id=\"" . $info['id_connection_icon'] . "\" class=\"div_header_connection_type\">
<!-- Connection type (wifi,3G etc)-->
<div id=\"" . $info['id_connection_icon'] . "_connection\" style=\"width:100%;height:50%;background-image: none;background-repeat: no-repeat;background-position: center center;background-size : auto 60%;\">
</div>
<!-- GPS indicator -->
<div id=\"" . $info['id_connection_icon'] . "_gps\" style=\"width:100%;height:50%;background-image: none;background-repeat: no-repeat;background-position: center center;background-size : auto 70%; background-image: url('" . IMAGES_PATH . "app/gps_indicator_off.png');\">
</div>
</div>
<!-- Rigth header -->
<div class=\"div_right_header\">
<div class=\"div_right_header_login_button\" id=\"" . $info['id_login_button'] . "\">
" . _("" . strtoupper(_($info['text_login_button'])) . "") . "
</div>
</div>";
}
/*
* Name : place_footer($info)
* Parameters : $info[text_version]
* $info[text_version_number]
* $info[id_footer_button_one]
* $info[id_footer_button_two]
* $info[id_footer_button_three]
* $info[id_footer_button_four]
* Description : place footer
*/
function place_footer($info){
GLOBAL $_PAGE_INFO;
echo"
<!-- Footer_button_1 store Button footer -->
<div class=\"footer_button_1\" id=\"" . $info['id_footer_button_one'] . "\" ></div>
<!-- Footer_button_2 home Button footer -->
<div class=\"footer_button_2\" id=\"" . $info['id_footer_button_two'] . "\" ></div>
<!-- Footer_button_3 home Button footer -->
<div class=\"footer_button_3\" id=\"" . $info['id_footer_button_three'] . "\" ></div>
<!-- Footer_button_4 home Button footer -->
<div class=\"footer_button_4\" id=\"" . $info['id_footer_button_four'] . "\" ></div>
<!-- Company logo footer -->
<div class=\"div_logo_footer\">
<!-- user name -->
<div class=\"div_username\">
<span class=\"div_version_text\"> " . strtoupper("" . $info['text_version'] . ": " . ((is_ReleaseCandidate()) ? $_SESSION[$_PAGE_INFO['id']]['release_dir'] : $info['text_version_number'] )) . "</span>
</div>
<!-- version number -->
<div class=\"div_version\">
<span class=\"div_username_text\"> ". strtoupper(checkSizeUsername($_SESSION[$_PAGE_INFO['id']]['login']['user']['name'])) ."</span>
</div>
</div>";
}
/*
* Name : parse_rtstatus($zkl_status)
* Parameters : $zkl_status
*
* Description : partse the real time status into array
*/
function parse_rtstatus($zkl_status) {
// Remove tags
$tmp = explode('},{',$zkl_status);
if (is_array($tmp)) {
unset($zkl_status);
// Remove tags
$tmp[0] = str_replace("/*ZKLsu1.0*/ZKL_Status=[{", "", $tmp[0]);
$tmp[sizeof($tmp)-1] = str_replace("}];", "", $tmp[sizeof($tmp)-1]);
// Split to array
for($i=0; $i<sizeof($tmp); $i++) {
$tmp_array = explode("\",", $tmp[$i]);
// Create associated array
if (is_array($tmp_array)) {
for($j=0; $j<sizeof($tmp_array); $j++) {
$key = explode(":\"",$tmp_array[$j]);
$zkl_status[$i][$key[0]] = str_replace("\"",'',$key[1]);
}
}
}
}
return $zkl_status;
}
?>