Location: PHPKode > projects > Yoxel Systems > yoxel_v1.24beta/lms/lms_admin_keys.php
<?php
// $Header: /home/CVS/rps/lms/lms_admin_keys.php,v 1.6 2007/11/25 21:52:44 yoxel Exp $
/*
 * ----START-LICENCE----
 * Copyright 2002-2008 Yoxel Systems, Santa Clara, CA, USA (hide@address.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * -----END-LICENCE-----
 */

	$RequireLogin=1;
  	require_once('../includes/db.inc');
	require_once('includes/lms/lms.inc');

	$rts = new LicenseManager;

	$pqt = $rts->get_pq_title();

	$page_title="Define License Keys";
	include_once('includes/header.inc');

	if($is_customer)
		_quit_error("You are not allowed to use this part of the site.");

	$uperm=UPERM_READ;
	if($user_is&USER_IS_M)
		$uperm|=UPERM_ADD|UPERM_EDIT;

	if($user_is&USER_IS_MU)
		$uperm|=UPERM_DEL;

	$pkid=0;
	if(isset($_POST['which_form'])){
		$wf=$_POST['which_form'];
		$pkid = $_POST['pkid'];
		$ok2sql=TRUE;
		$opt=$nopt=0;

		if(($wf == 'addc') || ($wf == 'editc')){
			if(isset($_POST['kpid']))
				$kpid=$_POST['kpid'];
			else
				_die(__FILE__.':'. __LINE__.' No product specified. ');

			$kn=stripslashes(trim($_POST['key_name']));
			if(!$rts->is_key_name($kn)){
				$ok2sql=FALSE;
				error_display('err_kname');
			}

			$ks=stripslashes(trim($_POST['key_summary']));
			if(!is_synopsis($ks)){
				$ok2sql=FALSE;
				error_display('err_ksum');
			}

			$kd=stripslashes(trim($_POST['key_descr']));
			if(!empty($kd)){
				if(!is_description($kd)){
					$ok2sql=FALSE;
					_live_error('Please enter a valid long description.');
					error_display('err_kdescr');
				}
			}

			$ikp=stripslashes(trim($_POST['init_price']));
			if(!empty($ikp)){
				if(!is_fpnum($ikp)){
					$ok2sql=FALSE;
					error_display('err_iprice');
				}
				if($_POST['iprel']=="yes")
					$opt|=LMS_KEYS_OPT_REL;
				else
					$nopt|=LMS_KEYS_OPT_REL;
			}

			$tkp=stripslashes(trim($_POST['tbl_price']));
			if(!empty($tkp)){
				if(!is_fpnum($tkp)){
					$ok2sql=FALSE;
					error_display('err_tprice');
				}
			}

			$bkp=stripslashes(trim($_POST['bill_price']));
			if(!empty($bkp)){
				if(!is_fpnum($bkp)){
					$ok2sql=FALSE;
					error_display('err_bprice');
				}
				$bpt=$_POST['bptype'];
			}
		}

		$k2v=array('name'=>$kn,
			'pid'=>$kpid,
			'summary'=>$ks,
			'description'=>$kd,
			'init_price'=>$ikp,
			'tbl_price'=>$tkp,
			'bill_price'=>$bkp,
			'bptype'=>$bkp?$bpt:'');

		if($wf == 'addc'){
			if($pkid)
				_die('pkid parameter is supposed to be 0 here.');

			if($ok2sql){
				if(!$rts->key_exists($kn)){
					$k2v['options']=$opt;
					$pkid=$rts->key_add($k2v);
					$_POST=array();
				}else{
					_live_error('A key with the same name already exists.');
					error_display('err_kexists');
				}
			}
			header("Location: ".$_SERVER['PHP_SELF']."?pkid=$pkid");
			exit;
		}elseif($pkid && ($wf == 'editc')){
			if($ok2sql){
				if(!$rts->key_exists($kn,$pkid) && ($krow=$rts->get_krow($kpid))){
					$opt|=$krow['options'];
					$k2v['options']=$opt&~$nopt;
					$rts->key_update($pkid,$k2v);
					$_POST=array();
				}else{
					_live_error(' A key with the same name already exists.');
					error_display('err_kexists');
				}
			}
			header("Location: ".$_SERVER['PHP_SELF']."?pkid=$pkid");
			exit;
		}elseif($pkid && ($wf == 'delete')){
			//echo "Del <br>";
			if($rts->key_has_requests($pkid))
				error_alert('There are license requests associated with this key.');
			else{
				$rts->key_remove($pkid);
				$pkid=0;
				$_POST=array();
			}
			header("Location: ".$_SERVER['PHP_SELF']."?pkid=$pkid");
			exit;
		}else
			_die('Unknown POST mode');

	}

	if(isset($_GET['pkid'])){
		$pkid=$_GET['pkid'];
	}

	$pqs_2d=&$rts->init_pqs(TRUE,TRUE);
	$pqs=&$pqs_2d['name'];
?>

<script>
<!--

function go_submit(form,action){
	if (action == "delete") {
	 	if(!confirm('Are you sure you want to delete this key?'))
			return;
	}else{
		if (text_check(form.key_name))
                	return alert("Please, enter key name.");

                if (sel_check(form.kpid))
                	return alert("Please, select product name.");

		if (text_check(form.key_summary))
                	return alert("Please, enter short summary.");

		if (form.key_descr.value)
			if(text_check(form.key_descr))
                		return alert("Please, enter correct long summary.");

		if (form.init_price.value)
			if(num_check(form.init_price))
                		return alert("Please, enter correct installation fee.");

		if (form.tbl_price.value)
			if(num_check(form.tbl_price))
                		return alert("Please, enter correct TBL monthly price.");

		if (form.bill_price.value){
			if(num_check(form.bill_price))
                		return alert("Please, enter correct billing price.");
			if(form.bill_price.value>0)
				if(sel_check(form.bptype))
                			return alert("Please, select billing frequency.");
		}
	}

	form.which_form.value=action;
	collect_all(form);
	form.submit();
	disable_form(form);

}
//-->
</script>
<table border='0' cellpadding='0' cellspacing='1' width='95%' class="dgray" align="center">
<tr>
	<th colspan="2">License Keys (feature names)</th>
</tr>
<tr style="height: 1" class="separator">
	<td colspan="2"></td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Key/Feature Name</th></tr>
		<tr><td>Either create a new key or pick an existing one for editing.</td></tr>
	</table>
	</td>
</tr>
<?php
		echo '
<tr class="lgray">
	<form action="'.$_SERVER['PHP_SELF'].'">
	<th width="30%">License Key</th>
	<td width="70%" align="left">
		<select class="selec" style="width: 24em" name="pkid" onChange="this.form.submit()">
		<option value="">=New=</option>';

	$krow=array();
	for($row=$rts->first_key();$row;$row=$rts->next_key()){
			echo '
			<option value="'.$row['kid'].'"'.($row['kid'] == $pkid?' selected':'').'>'.$row['name'].'</option>';
			if($row['kid'] == $pkid)
				$krow=$row;
	}
	if(count($krow)<1)
		$pkid=0;

	echo '
		</select>
	</td>
	</form>
</tr>
<tr class="lgray">
</tr>
	<form action="'.$_SERVER['PHP_SELF'].'" method="post">
	<input type=hidden name="which_form" value="">
	<input type=hidden name="pkid" value="'.$pkid.'">
<tr class="lgray">
	<th width="30%" valign="top">Key Name</th>
	<td width=70%>
			<input class="inp" type="text" name="key_name" size="32" maxlength="127" value="';
		if(isset($_POST['key_name']))
			echo $_POST['key_name'];
		elseif($pkid>0)
			echo $krow['name'];
		echo '" />';

		echo '<br>Example: FEATUREA, ProductB_Main_Engine, ProductB_ExtraFeature1, ...<br>
			<span id="err_kname" class="small" style="display:none">Please enter a valid key name (alphanumeric, no spaces).</span>';
	echo '
	</td>
</tr>
<tr id="err_kexists" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>A key with the same name already exists.</td>
</tr>';

	echo '
<tr style="height: 1" class="separator">
	<td colspan="2"></td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Product Assignment</th></tr>
		<tr><td>Each key probably enables a certain feature within your product. Specify the association with the product here.</td></tr>
	</table>
	</td>
</tr>
<tr class="lgray">
	<th width="30%">'.$pqt.'</th>
	<td width=70%>
		<select class="selec" style="width: 16em" name="kpid">
			<option value="">=Product=</option>';
			foreach ($pqs as $k => $v) {
				if($pqs_2d['parent'][$k])
					continue;
				if(($pkid && ($k == $krow['pid'])))
					echo "<option value='$k' selected>$v</option>";
				else
					echo "<option value='$k'>$v</option>";
			}
			echo '
		</select>
	</td>
</tr>';

	echo '
<tr style="height: 1" class="separator">
	<td colspan="2"></td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Descriptions</th></tr>
		<tr><td>Short, one line description will be used when referring to this key in Yoxel. Long description is the details that you would like to keep around so other users have clear idea what the feature is for.</td></tr>
	</table>
	</td>
</tr>
<tr class="lgray">
	<th width="30%">Short Description</th>
	<td width=70%>
		<input class="inp" type="text" name="key_summary" size="48" maxlength="127" value="';
		if(isset($_POST['key_summary']))
			echo $_POST['key_summary'];
		elseif($pkid>0)
			echo $krow['summary'];
		echo '" />
	</td>
</tr>
<tr id="err_ksum" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>Please enter a valid short description.</td>
</tr>
<tr class="lgray">
	<th width="30%">Long Description</th>
	<td width=70%>
			<textarea name="key_descr" rows="8" style="width: 98%">';
		if(isset($_POST['key_descr']))
			echo $_POST['key_descr'];
		elseif($pkid>0)
			echo $krow['description'];
		echo ' </textarea>
	</td>
</tr>
<tr id="err_kdescr" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>Please enter a valid long description.</td>
</tr>';

	echo '
<tr style="height: 1" class="separator">
	<td colspan="2"></td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Initial shipment or Major upgrade</th></tr>
		<tr><td>The amount that is charged once per shipped product/feature or per each new major version of the product.</td></tr>
	</table>
	</td>
</tr>
<tr class="lgray">
	<th width="30%">Installation fee</th>
	<td width=70%>
			$<input class="inp" type="text" name="init_price" size="9" maxlength="12" value="';
		if(isset($_POST['init_price']))
			echo $_POST['init_price'];
		elseif($pkid>0)
			echo $krow['init_price'];
		echo '" />
			<input type="radio" name="iprel" value="no" checked> once-off
			<input type="radio" name="iprel" value="yes"> per major version
	</td>
</tr>
<tr id="err_iprice" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>Please enter a valid price.</td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Time Based Licensing</th></tr>
		<tr><td>This monthly price value could help you compute total booking amount when creating a pre-payment expiration-date based license.</td></tr>
	</table>
	</td>
</tr>
<tr class="lgray">
	<th width="30%">Monthly price</th>
	<td width=70%>
			$<input class="inp" type="text" name="tbl_price" size="9" maxlength="12" value="';
		if(isset($_POST['tbl_price']))
			echo $_POST['tbl_price'];
		elseif($pkid>0)
			echo $krow['tbl_price'];
		echo '" />
	</td>
</tr>
<tr id="err_tprice" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>Please enter a valid price.</td>
</tr>
<tr class="lgray">
	<td width="30%"></td>
	<td>
	<table width="100%" border=0 class="small">
		<tr><th align=right valign=top>Maintenance and Billing</th></tr>
		<tr><td>The amount you intend to bill periodically for maintenence/support or as deffered payment.</td></tr>
	</table>
	</td>
</tr>
<tr class="lgray">
	<th width="30%">Billing price</th>
	<td width=70%>
			$<input class="inp" type="text" name="bill_price" size="9" maxlength="12" value="';
		if(isset($_POST['bill_price']))
			echo $_POST['bill_price'];
		elseif($pkid>0)
			echo $krow['bill_price'];
		echo '" />
			<select class="selec" name="bptype">
			<option value="">=Frequency=</option>';
		foreach($bptype2str as $bpt => $s)
			echo '
			<option value="'.$bpt.'"'.($krow['bptype']==$bpt?' selected':'').'>'.$s.'</option>';
		echo '
			</select>
	</td>
</tr>
<tr id="err_bprice" class="lgray small" style="display:none">
	<td>&nbsp;</td>
	<td>Please enter a valid price.</td>
</tr>';

	echo '
<tr style="background: white">
	<th colspan="2">';
	if($pkid>0)
		echo '
		<input class=wbtn type="button" value="Edit" onClick="go_submit(this.form,\'editc\')"'.($uperm&UPERM_EDIT?'':' disabled').'>
		<input class=wbtn type="button" value="Delete "onClick="go_submit(this.form,\'delete\')"'.($uperm&UPERM_DEL?'':' disabled').'>';
	else
		echo '<input class=wbtn type="button" value="Add" onClick="go_submit(this.form,\'addc\')"'.($uperm&UPERM_ADD?'':' disabled').'>';
?>
	</th>
	</form>
</tr>
</table>


<?php include_once("includes/footer.inc"); ?>

Return current item: Yoxel Systems