Location: PHPKode > scripts > Support Tickets Center > zingiri-tickets/zing_tickets_cp.php
<?php
$zing_tickets_name = "Support Tickets Center";
$zing_tickets_shortname = "zing_tickets";
$install_type = array("Clean" );
$zing_login_type = array("osTickets","WP");

$zing_tickets_options = array (

array(  "name" => "General settings",
            "type" => "heading",
			"desc" => "This section manages the Support Tickets Center settings.",
),
array(	"name" => "Type of integration",
			"desc" => "Select the way you want to login. If you want to use your Wordpress users, select 'WP'. <br />If you want to use the osTickets users, select 'osTickets'",
			"id" => $zing_tickets_shortname."_login",
			"std" => "WP",
			"type" => "select",
			"options" => $zing_login_type),
array(	"name" => "Type of access",
			"desc" => "In case of Wordpress integration, select the way you want guests to access the ticketing system. <br />You can restrict this to Subscribers only or leave it open to everyone",
			"id" => $zing_tickets_shortname."_subscribers",
			"std" => "WP",
			"type" => "select",
			"options" => array("Subscribers","Everyone")),
array(	"name" => "Language",
			"desc" => "Language of ticketing system (customer front end only)",
			"id" => $zing_tickets_shortname."_lang",
			"std" => "en",
			"type" => "select2",
			"options" => array("en"=>"English","es"=>"Spanish","nl"=>"Dutch")),
);

function zing_tickets_add_admin() {
	
	global $zing_tickets_name, $zing_tickets_shortname, $zing_tickets_options, $zing_tickets_menu, $zing_tickets_mode,$zing_tickets_submenu,$zing_tickets_active_menu;

	if (isset($_GET['page']) &&  ($_GET['page'] == 'zingiri-tickets-admin') ) {

		if (isset($_REQUEST['action']) && ('update' == $_REQUEST['action']) ) {
			zing_tickets_activate();
			foreach ($zing_tickets_options as $value) {
				if( isset( $_REQUEST[ $value['id'] ] ) ) {
					update_option( $value['id'], $_REQUEST[ $value['id'] ]  );
				} else { delete_option( $value['id'] );
				}
			}
			header("Location: options-general.php?page=zingiri-tickets-admin");
			die;
		}

		if (isset($_REQUEST['action']) && ('install' == $_REQUEST['action']) ) {
			zing_tickets_activate();
			foreach ($zing_tickets_options as $value) {
				if( isset( $_REQUEST[ $value['id'] ] ) ) {
					update_option( $value['id'], $_REQUEST[ $value['id'] ]  );
				} else { delete_option( $value['id'] );
				}
			}
			header("Location: options-general.php?page=zingiri-tickets-admin&installed=true");
			die;
		}

	}
	if (!isset($_GET['zscp']) || !$_GET['zscp']) {
		$zing_tickets_mode='menu';
	}
	zing_tickets_ostickets_content();
	if (current_user_can('activate_plugins')) {
		add_menu_page($zing_tickets_name, $zing_tickets_name, 'edit_pages', 'zingiri-tickets-admin','zing_tickets_admin');
		add_submenu_page('zingiri-tickets-admin', $zing_tickets_name.'- Integration', 'Integration', 'activate_plugins', 'zingiri-tickets-admin', 'zing_tickets_admin');
	} else {
		add_menu_page($zing_tickets_name, $zing_tickets_name, 'edit_pages', 'zingiri-tickets-admin','zing_ost_admin');
	}
	if (count($zing_tickets_menu) > 0) {
		foreach ($zing_tickets_menu as $i => $menu) {
			$link=preg_replace('/.*page=zingiri-tickets-admin&(.*?)/','$1',$menu[1]);
			if (!current_user_can('activate_plugins') && strstr($link,'index'))
				add_submenu_page('zingiri-tickets-admin', $zing_tickets_name.'-'.$menu[0], $menu[0], 'edit_pages', 'zingiri-tickets-admin', 'zing_ost_admin');
			else
				add_submenu_page('zingiri-tickets-admin', $zing_tickets_name.'-'.$menu[0], $menu[0], 'edit_pages', 'zingiri-tickets-admin&'.$link, 'zing_ost_admin');
			if ($i == $zing_tickets_active_menu) {
				foreach ($zing_tickets_submenu as $submenu) {
					$link=preg_replace('/.*page=zingiri-tickets-admin&(.*?)/','$1',$submenu[1]);
					add_submenu_page('zingiri-tickets-admin', $zing_tickets_name.'-'.$submenu[0], '- '.$submenu[0], 'edit_pages', 'zingiri-tickets-admin&'.$link, 'zing_ost_admin');
				}
			}
		}
	}
}

function zing_ost_admin() {
	global $zing_tickets_content;
	global $zing_tickets_menu;

	echo '<div style="width:80%;float:left;position:relative">';
	echo $zing_tickets_content;
	echo '</div>';

	require(dirname(__FILE__).'/support-us.inc.php');
}

function zing_tickets_admin() {
	global $zing_tickets_name, $zing_tickets_shortname, $zing_tickets_options, $wpdb;

	if (isset($_GET['zscp']) && $_GET['zscp']) {
		zing_ost_admin();
		return;
	}

	if ( isset($_REQUEST['installed']) && $_REQUEST['installed'] ) echo '<div id="message" class="updated fade"><p><strong>'.$zing_tickets_name.' installed.</strong></p></div>';

	?>
<div class="wrap">
<div style="width: 75%; float: left; position: relative; min-height: 500px;">
<h2><b>Support Tickets Center</b></h2>

	<?php
	$zing_tickets_version=get_option("zing_tickets_version");

	?>
<form method="post">

<table class="optiontable">

<?php foreach ($zing_tickets_options as $value) {

	if ($value['type'] == "text") { ?>

	<tr align="left">
		<th scope="row"><?php echo $value['name']; ?>:</th>
		<td><input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"
			type="<?php echo $value['type']; ?>"
			value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>"
			size="40"
		/></td>

	</tr>
	<tr>
		<td colspan=2><small><?php echo $value['desc']; ?> </small>
		<hr />
		</td>
	</tr>

	<?php } elseif ($value['type'] == "textarea") { ?>
	<tr align="left">
		<th scope="row"><?php echo $value['name']; ?>:</th>
		<td><textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="50"
			rows="8"
		/> <?php if ( get_option( $value['id'] ) != "") { echo stripslashes (get_option( $value['id'] )); }
		else { echo $value['std'];
		} ?> </textarea></td>

	</tr>
	<tr>
		<td colspan=2><small><?php echo $value['desc']; ?> </small>
		<hr />
		</td>
	</tr>

	<?php } elseif ($value['type'] == "select") { ?>

	<tr align="left">
		<th scope="top"><?php echo $value['name']; ?>:</th>
		<td><select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
		<?php foreach ($value['options'] as $option) { ?>
			<option <?php if ( get_option( $value['id'] ) == $option) { echo ' selected="selected"'; }?>><?php echo $option; ?></option>
			<?php } ?>
		</select></td>

	</tr>
	<tr>
		<td colspan=2><small><?php echo $value['desc']; ?> </small>
		<hr />
		</td>
	</tr>

	<?php } elseif ($value['type'] == "select2") { ?>

	<tr align="left">
		<th scope="top"><?php echo $value['name']; ?>:</th>
		<td><select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
		<?php foreach ($value['options'] as $option => $label) { ?>
			<option value="<?php echo $option?>"
			<?php if ( get_option( $value['id'] ) == $option) { echo ' selected="selected"'; }?>
			><?php echo $label; ?></option>
			<?php } ?>
		</select></td>

	</tr>
	<tr>
		<td colspan=2><small><?php echo $value['desc']; ?> </small>
		<hr />
		</td>
	</tr>

	<?php } elseif ($value['type'] == "heading") { ?>

	<tr valign="top">
		<td colspan="2" style="text-align: left;">
		<h2 style="color: green;"><?php echo $value['name']; ?></h2>
		</td>
	</tr>
	<tr>
		<td colspan=2><small>
		<p style="color: red; margin: 0 0;"><?php echo $value['desc']; ?></P>
		</small>
		<hr />
		</td>
	</tr>

	<?php } ?>
	<?php
}
?>
</table>

<?php if (!$zing_tickets_version) { ?>
<p class="submit"><input name="install" type="submit" value="Install" /> <input type="hidden"
	name="action" value="install"
/></p>

<?php } elseif ($zing_tickets_version != ZING_TICKETS_VERSION) { ?>
<p class="submit"><input name="install" type="submit" value="Upgrade" /> <input type="hidden"
	name="action" value="install"
/></p>

<?php } else { ?>

<p class="submit"><input name="install" type="submit" value="Update" /> <input type="hidden"
	name="action" value="update"
/></p>

<?php } ?></form>
<hr />
<p>The following Wordpress users are active osTicket users</p>
<?php if ($zing_tickets_version) {
	$prefix=$wpdb->prefix."zing_ost_";

	$query="select * from `##users`,`##usermeta` where `##users`.`ID`=`##usermeta`.`user_id` and `##usermeta`.`meta_key`='wp_user_level'";
	$query=str_replace("##",$wpdb->prefix,$query);
	$sql = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($sql)) {
		if (!isset($row['first_name'])) $row['first_name']='';
		if (!isset($row['last_name'])) $row['last_name']=$row['display_name'];
		if ($row['meta_value'] >= 8) { //administrator role
			$query2="REPLACE INTO `".$prefix."staff` (`staff_id`, `group_id`, `dept_id`, `username`, `firstname`, `lastname`, `passwd`, `email`, `phone`, `phone_ext`, `mobile`, `signature`, `isactive`, `isadmin`, `isvisible`, `onvacation`, `daylight_saving`, `append_signature`, `change_passwd`, `timezone_offset`, `max_page_size`, `created`, `lastlogin`, `updated`) VALUES";
			$query2.="('".$row['ID']."', 1, 1, '".$row['user_login']."', '".$row['first_name']."', '".$row['last_name']."', '".md5($row['user_pass'])."', '".$row['user_email']."', '', '', '', '', 1, 1, 1, 0, 0, 0, 0, 0.0, 0, '".date("Y-m-d")."', NULL, '".date("Y-m-d")."')";
			$wpdb->query($query2);
			$query2=sprintf("UPDATE `".$prefix."staff` SET `passwd`='%s', `isadmin`=1, `change_passwd`=0 WHERE `username`='%s'",md5($row['user_pass']),$row['user_login']);
			$wpdb->query($query2);
		} elseif ($row['meta_value'] >= 5) { //editor role
			$query2="REPLACE INTO `".$prefix."staff` (`staff_id`, `group_id`, `dept_id`, `username`, `firstname`, `lastname`, `passwd`, `email`, `phone`, `phone_ext`, `mobile`, `signature`, `isactive`, `isadmin`, `isvisible`, `onvacation`, `daylight_saving`, `append_signature`, `change_passwd`, `timezone_offset`, `max_page_size`, `created`, `lastlogin`, `updated`) VALUES";
			$query2.="('".$row['ID']."', 1, 1, '".$row['user_login']."', '".$row['first_name']."', '".$row['last_name']."', '".md5($row['user_pass'])."', '".$row['user_email']."', '', '', '', '', 1, 0, 1, 0, 0, 0, 0, 0.0, 0, '".date("Y-m-d")."', NULL, '".date("Y-m-d")."')";
			$wpdb->query($query2);
			$query2=sprintf("UPDATE `".$prefix."staff` SET `passwd`='%s', `isadmin`=0, `change_passwd`=0 WHERE `username`='%s'",md5($row['user_pass']),$row['user_login']);
			$wpdb->query($query2);
		} else {
			$query2=sprintf("DELETE FROM `".$prefix."staff` WHERE `username`='%s'",$row['user_login']);
			$wpdb->query($query2);
		}
		$level[$row['user_login']]=$row['meta_value'];
	}
	$query="select * from `##users`,`##zing_ost_staff` where `##users`.`user_login`=`##zing_ost_staff`.`username`";
	$query=str_replace("##",$wpdb->prefix,$query);
	$sql = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($sql)) {
		echo $row['user_login'].' - '.$row['firstname'].' - '.$row['user_email'];
		if ($level[$row['user_login']] >= 8) echo ' - admin';
		elseif ($level[$row['user_login']] >= 5) echo ' - staff';

		if (md5($row['user_pass']) != $row['passwd']) echo '!Password not synchronised';
		echo '<br />';
	}

	?> <br />
	<?php } ?>
<hr />
</div>
	<?php 	require(dirname(__FILE__).'/support-us.inc.php'); ?></div>
	<?php
}
add_action('admin_menu', 'zing_tickets_add_admin');
?>
Return current item: Support Tickets Center