ticket_userinfo

Contribuer au projet de part vos connaissances: PHP, HTML, CSS, SQL, JS ....
Répondre
massivity
Gsup LEVEL 2
Messages : 35
Enregistré le : mar. 27 sept. 2016 15:23

Bonjour,

Je souhaite afficher des informations utilisateurs supplémentaires dans le ticket, j'ai modifier les fichiers suivants mais sans success :

Code : Tout sélectionner

<?php 
################################################################################
# @Name : ticket_userinfos.php
# @Description : get user information to display on ticket
# @call : ticket.php over ajax
# @parameters : 
# @Author : Flox
# @Create : 25/01/2019
# @Update : 27/08/2020
# @Version : 3.2.4
################################################################################

//initialize variables 
if(!isset($_GET['token'])) $_GET['token']=''; 
$_GET['token']=htmlspecialchars($_GET['token'], ENT_QUOTES, 'UTF-8');
if(!isset($_COOKIE['token'])) $_COOKIE['token']=''; 

//security check
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{
	//check post value and token
	if($_POST['user'] && $_GET['token']==$_COOKIE['token'] && $_GET['token'])
	{
		//init var
		$service='';
		$agency='';
		$other_ticket='';
		
		//db connect
		require('../connect.php');
		
		//load parameters table
		$qry=$db->prepare("SELECT * FROM `tparameters`");
		$qry->execute();
		$rparameters=$qry->fetch();
		$qry->closeCursor();
		
		//display error parameter
		if($rparameters['debug']) {
			ini_set('display_errors', 'On');
			ini_set('display_startup_errors', 'On');
			ini_set('html_errors', 'On');
			error_reporting(E_ALL);
		} else {
			ini_set('display_errors', 'Off');
			ini_set('display_startup_errors', 'Off');
			ini_set('html_errors', 'Off');
			error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
		}
		
		//get user data
		$qry=$db->prepare("SELECT `phone`,`mobile`,`mail`,`function`,[b]`custom1`,`custom2`[/b],`company` FROM `tusers` WHERE id=:id");
		$qry->execute(array('id' => $_POST['user']));
		$user=$qry->fetch();
		$qry->closeCursor();
		
		$qry=$db->prepare("SELECT `name` FROM `tcompany` WHERE id=:id AND id!=0");
		$qry->execute(array('id' => $user['company']));
		$company=$qry->fetch();
		$qry->closeCursor();
		if(empty($company['name'])) {$company['name']='';}
		
		$qry=$db->prepare("SELECT `name` FROM `tservices`,`tusers_services` WHERE `tservices`.`id`=`tusers_services`.`service_id` AND `tusers_services`.`user_id`=:user_id AND `tservices`.`disable`=0");
		$qry->execute(array('user_id' => $_POST['user']));
		while($row=$qry->fetch()) {$service.=' '.$row['name'];}
		$qry->closeCursor();
		
		$qry=$db->prepare("SELECT `name` FROM `tagencies` WHERE `id` IN (SELECT `agency_id` FROM `tusers_agencies` WHERE `user_id`=:user_id) AND `disable`=0");
		$qry->execute(array('user_id' => $_POST['user']));
		while($row=$qry->fetch()) {$agency.=' '.$row['name'];}
		$qry->closeCursor();
		
		$qry=$db->prepare("SELECT `id`,`title` FROM `tincidents` WHERE user=:user_id AND (`state`='1' OR `state`='2' OR `state`='6' OR `state`='5') AND `id`!=:ticket AND `disable`=0 ORDER BY id DESC LIMIT 0,3");
		$qry->execute(array('user_id' => $_POST['user'],'ticket' => $_GET['ticket']));
		while($row=$qry->fetch()) {$other_ticket.='&nbsp;<a title="'.$row['title'].'" href="./index.php?page=ticket&amp;id='.$row['id'].'">#'.$row['id'].'</a>';}
		$qry->closeCursor();
		
		$qry = $db->prepare("SELECT `id`,`netbios` FROM `tassets` WHERE `user`=:user_id AND `state`='2' AND `user`!='0' AND `disable`='0' ORDER BY id DESC");
		$qry->execute(array('user_id' => $_POST['user']));
		$asset=$qry->fetch();
		$qry->closeCursor(); 
		if(empty($asset['id'])) {$asset['id']='';}
		if(empty($asset['netbios'])) {$asset['netbios']='';}
		
		//check if company limit tickets
		if($rparameters['company_limit_ticket'] )
		{
			$qry=$db->prepare("SELECT `tcompany`.`id`,`tcompany`.`limit_ticket_number`,`tcompany`.`limit_ticket_days`,`tcompany`.`limit_ticket_date_start` FROM `tcompany`,`tusers` WHERE `tusers`.`company`=`tcompany`.`id` AND `tusers`.id=:id");
			$qry->execute(array('id' => $_POST['user']));
			$rcompany=$qry->fetch();
			$qry->closeCursor();
			
			if($rcompany['limit_ticket_days']!=0 && $rcompany['limit_ticket_date_start']!='0000-00-00')
			{
				//generate date start and date end
				$date_start=$rcompany['limit_ticket_date_start'];
				
				//calculate end date	
				$date_start_conv = date_create($rcompany['limit_ticket_date_start']);
				date_add($date_start_conv, date_interval_create_from_date_string("$rcompany[limit_ticket_days] days"));
				$date_end=date_format($date_start_conv, 'Y-m-d');
			
				//count number of ticket remaining in period
				$qry=$db->prepare("SELECT COUNT(tincidents.id) FROM `tincidents`,`tusers` WHERE tusers.id=tincidents.user AND tusers.company=:company AND date_create BETWEEN :date_start AND :date_end AND tincidents.disable='0'");
				$qry->execute(array('company' => $rcompany['id'],'date_start' => $date_start,'date_end' => $date_end));
				$nbticketused=$qry->fetch();
				$qry->closeCursor();
				
				//check number of tickets in current range date
				if (date('Y-m-d')>$date_end || date('Y-m-d')<$date_start)
				{
					$nbticketremaining=0;
				} else {
					$nbticketremaining=$rcompany['limit_ticket_number']-$nbticketused[0];
				}
			} else {$nbticketremaining='';}
		} else {$nbticketremaining='';}
		
		//check if company hour tickets
		if($rparameters['company_limit_hour'] )
		{
			$qry=$db->prepare("SELECT `tcompany`.`id`,`tcompany`.`limit_hour_number`,`tcompany`.`limit_hour_days`,`tcompany`.`limit_hour_date_start` FROM `tcompany`,`tusers` WHERE `tusers`.`company`=`tcompany`.`id` AND `tusers`.id=:id");
			$qry->execute(array('id' => $_POST['user']));
			$rcompany=$qry->fetch();
			$qry->closeCursor();
			
			if($rcompany['limit_hour_days']!=0 && $rcompany['limit_hour_date_start']!='0000-00-00')
			{
				//generate date start and date end
				$date_start=$rcompany['limit_hour_date_start'];
				
				//calculate end date	
				$date_start_conv = date_create($rcompany['limit_hour_date_start']);
				date_add($date_start_conv, date_interval_create_from_date_string("$rcompany[limit_hour_days] days"));
				$date_end=date_format($date_start_conv, 'Y-m-d');
			
				//count number of ticket remaining in period
				$qry=$db->prepare("SELECT SUM(tincidents.time)/60 FROM `tincidents`,`tusers` WHERE tusers.id=tincidents.user AND tusers.company=:company AND date_create BETWEEN :date_start AND :date_end AND tincidents.disable='0'");
				$qry->execute(array('company' => $rcompany['id'],'date_start' => $date_start,'date_end' => $date_end));
				$nbhourused=$qry->fetch();
				$qry->closeCursor();
				//check number of tickets in current range date
				if (date('Y-m-d')>$date_end || date('Y-m-d')<$date_start)
				{
					$nbhourremaining=0;
				} else {
					$nbhourremaining=$rcompany['limit_hour_number']-$nbhourused[0];
					$nbhourremaining=round($nbhourremaining,1);
				}
			} else {$nbhourremaining='';}
		} else {$nbhourremaining='';}
		
		//encode result ajax call
		if($user) {
			echo json_encode(
				array(
					"status" => "success",
					"phone" => $user["phone"],
					"mobile" => $user["mobile"],
					"mail" => $user["mail"],
					"function" => $user["function"],
					"company" => $company["name"],
					"service" => $service,
                                        [b] "custom1" => $custom1,
                                         "custom2" => $custom2,[/b]
					"agency" => $agency,
					"asset_id" => $asset['id'],
					"asset_netbios" => $asset['netbios'],
					"other_ticket" => $other_ticket,
					"ticket_remaining" => $nbticketremaining,
					"hour_remaining" => $nbhourremaining
				)
			);
		} else {
			echo json_encode(array("status" => "failed"));
		}
		 //close database access
		$db = null;
	} else {
		echo json_encode(array("status" => "failed"));
	} 
} else {
	echo json_encode(array("status" => "failed"));
}
?>

Egalement dans le fichier suivant :
ticket.php

Code : Tout sélectionner

<!-- START user info part -->
						<?php
							if($mobile==0)
							{
								//data get by ajax script refer /includes/
								echo '
								<span style="font-size:15px;">
									<span id="user_phone"></span>
									<span id="user_mobile"></span>
									<span id="user_mail"></span>
									<span id="user_function"></span>
									<span id="user_service"></span>
                                                                         <span id="user_custom1"></span>
									<span id="user_agency"></span>
									';
									if(!$rright['ticket_user_company']) {echo '<span id="user_company"></span>';}
									echo '
									<span id="user_other_ticket"></span>
									<span id="user_asset"></span>
									<span id="user_ticket_remaining"></span>
									<span id="user_hour_remaining"></span>
								</span>
								';
							}
						?>
						<!-- START user info part -->
					</div>
				</div>
				<!-- END sender part -->

Code : Tout sélectionner

			//function to add user information to current page
			function GetUserInfos(user) {
				var dataString = "user="+user; 
				$.ajax({ 
					type: "POST", 
					url: "includes/ticket_userinfos.php?token=<?php echo $_COOKIE["token"]; ?>&ticket=<?php echo $_GET['id']; ?>", 
					data: dataString, 
					success: function(result){
						//console.log('JSON received :', result)
						var data = JSON.parse(result);
						if(data.phone) {$("#user_phone").html('&nbsp;&nbsp;<a href="tel:'+data.phone+'"><i title="<?php echo T_('Téléphoner au'); ?> '+data.phone+'" class="fa fa-phone text-info"></i></a> '+data.phone);} else {$("#user_phone").html('');}
						if(data.mobile) {$("#user_mobile").html('&nbsp;&nbsp;<a href="tel:'+data.mobile+'"><i title="<?php echo T_('Téléphoner au'); ?> '+data.mobile+'" class="fa fa-mobile text-info"></i></a> '+data.mobile);} else {$("#user_mobile").html('');}
						if(data.mail) {$("#user_mail").html('&nbsp;&nbsp;<a href="mailto:'+data.mail+'"><i title="<?php echo T_('Envoyer un mail sur'); ?> '+data.mail+'" class="fa fa-envelope text-info"></i></a>');} else {$("#user_mail").html('');}
						if(data.function) {$("#user_function").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Fonction'); ?> '+data.function+'" class="fa fa-user text-info"></i></a> '+data.function);} else {$("#user_function").html('');}
						if(data.service) {$("#user_service").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Service'); ?> '+data.service+'" class="fa fa-users text-info"></i></a> '+data.service);} else {$("#user_service").html('');}
                                                 if(data.custom1) {$("#user_custom1").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Nom Société'); ?> '+data.custom1+'" class="fa fa-users text-info"></i></a> '+data.custom1);} else {$("#user_custom1").html('');}
						if(data.agency) {$("#user_agency").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Agence'); ?> '+data.agency+'" class="fa fa-globe text-info"></i></a> '+data.agency);} else {$("#user_agency").html('');}
						if(data.company) {$("#user_company").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Société'); ?> '+data.company+'" class="fa fa-building text-info"></i></a> '+data.company);} else {$("#user_company").html('');}
						if(data.other_ticket) {$("#user_other_ticket").html('&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Autres tickets de cet utilisateur'); ?>" class="fa fa-ticket-alt text-info"></i></a>'+data.other_ticket);} else {$("#user_other_ticket").html('');}
						if(data.asset_id) {$("#user_asset").html('&nbsp;&nbsp;&nbsp;<a target="_blank" href="./index.php?page=asset&id='+data.asset_id+'"><i title="<?php echo T_('Équipement associé'); ?>" class="fa fa-desktop text-info"></i></a> '+data.asset_netbios);} else {$("#user_asset").html('');}
						if(data.ticket_remaining) {$("#user_ticket_remaining").html('&nbsp;&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Tickets restants'); ?>" class="fa fa-tachometer-alt text-info"></i></a> '+data.ticket_remaining);} else {$("#user_ticket_remaining").html('');}
						if(data.hour_remaining) {$("#user_hour_remaining").html('&nbsp;&nbsp;&nbsp;<a href=""><i title="<?php echo T_('Heures restantes'); ?>" class="fa fa-tachometer-alt text-info"></i></a> '+data.hour_remaining+'h');} else {$("#user_hour_remaining").html('');}
						$('#user_warning').css('display', 'none');
					}
				});
			}
Merci d'avance de votre aide
Serveur: GestSup: 3.2.31 | Nginx : 1.20.2 | MariaDB : 10.5.10 | PHP : 8.1.13
Avatar du membre
Flox
Administrateur du site
Messages : 9411
Enregistré le : jeu. 21 juin 2012 19:00

Bonjour,

Les champs personnalisé 1 et 2 seront affichées sur les informations demandeur dans la prochaine version 3.2.5.
2020-10-14 18_34_02_screenshot_gestsup.png
2020-10-14 18_34_02_screenshot_gestsup.png (3.59 Kio) Vu 10925 fois
Cdt
GestSup: 3.2.47 | Debian: 12 | Apache: 2.4.59 | MariaDB: 11.5.2 | PHP: 8.3.12 | https://doc.gestsup.fr/
massivity
Gsup LEVEL 2
Messages : 35
Enregistré le : mar. 27 sept. 2016 15:23

Bonjour,

Merci de votre retour,

J'attends avec impatience cette nouvelle version ;)
Serveur: GestSup: 3.2.31 | Nginx : 1.20.2 | MariaDB : 10.5.10 | PHP : 8.1.13
Répondre