Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/user/newfeature.php
<?php
/* +----------------------------------------------------------------------+
   | Netautor Professional Application Server                             |
   +----------------------------------------------------------------------+
   | Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net>      |
   +----------------------------------------------------------------------+
   | This file is subject to license, that is bundled with this package   |
   | in the file LICENSE.TXT, and is available at through the             |
   | world-wide-web at http://www.netautor.com/license/                   |
   |                                                                      |
   | If you did not receive a copy of the license and are unable to       |
   | obtain it through the world-wide-web, please send a note to          |
   | hide@address.com so we can mail you a copy.                      |
   +----------------------------------------------------------------------+
   | Authors: Stefan Rottensteiner <hide@address.com>    |
   |          Marek  Kadziela      <hide@address.com>	      |
   |          Gregor Wollner                                              |
   |          Christian Unger                                             |
   |          Helli  Kleinhans  									      |
   +----------------------------------------------------------------------+
   | @version	$Revision: 1.12 $										  |
   +----------------------------------------------------------------------+*/

/**
 * Create a new feature - executiv part
 */

include_once('../../include/init.inc');
if(	!$GLOBALS['USER']->check_feature('Admin') && ($user_id == 10 && !$GLOBALS['USER']->check_feature('ac_system') )	&& !$GLOBALS['USER']->check_feature('ac_user') )
{
	$GLOBALS['USER']->login_call();
}

//	---	include necessary functions
includeNaPro('form');

$GLOBALS['LOCALE']->textdomain('user');

if (!isset($button)) $button='';

function GetValue($data,$fto)
{
	$retval='';
	$max_fto = count($fto);
	for($i=0; $i< $max_fto ; $i++) {
		if($fto[$i]['fto_ft_id'] == $data['ft_id']) 	$retval[]=$fto[$i]['fto_value'];
	}
	return($retval);
}

function GetFeatures()
{
	global $LOCALE;

	$type_text = array(	'5'=>$GLOBALS['LOCALE']->gettext('boolean'),
						'4'=>$GLOBALS['LOCALE']->gettext('multi_value'),
						'3'=>$GLOBALS['LOCALE']->gettext('single_value')
					);

	$query = "SELECT *  FROM feature WHERE ft_area = '".$GLOBALS[ 'Area' ]."' ORDER BY ft_name";
	$erg = $GLOBALS[ 'sql_world' ]->select($query,0,0,2);

	$max 	= count($erg);
	$text 	= '';
	for( $i = 0; $i < $max ; $i++ )
	{
		$text.= '
				<tr class="bglistgrey">
					<td align="center" valign="center">
						<input 
							type="Checkbox" 
							name="feat['.$erg[$i]['ft_id'].']" value="'.$erg[$i]['ft_id'].'">
					</td>
					<td align="left" valign="center" class="text">
						'.$erg[$i]['ft_name'].'
					</td>
					<td align="left" valign="center" class="text">
					'.$type_text[ $erg[$i]['ft_type'] ].'
					</td>
					<td align="left" valign="center" class="text">
					'.($erg[$i]['ft_remark']).'
					</td>
				</tr>
				';
	}
	echo($text);

}

function create_new_area ()
{
	echo ("<script language='JavaScript' type='text/javascript'>
			<!--
			alert('Sorry, function not yet implemented');
			//-->
		 </script>");
}

if(isset($delete) && !empty($feat))
{
	foreach($feat as $name=>$wert)
	{
		if (empty($wert)) continue;

		$statements[]="DELETE from fto where fto_ft_id = {$wert}";
		$statements[]="DELETE from feature where ft_id = {$wert}";
	}
	
	$feedback = $sql_world->exec_multi($statements);
}

if(isset($create))
{
	/*
	* Allowed chars: a-z 0-9 and _
	*/
	$new_feature	=	preg_replace(array('/[^a-z0-9_]/','/^[_]{2,}/'),array('','_'),str_replace(' ','_',trim(strtolower($new_feature))));

	if ( (!empty($new_feature)) && (!empty($Area)) )
	{
		if (empty($remark)) $remark= $new_feature;
		if (!isset($ft_type)) $ft_type=3;

		// 5=boolean
		// 4=multi  text
		// 3=single text
		
		$ft_multiple	= ( $ft_type == 5 || $ft_type == 3 ? 0 : 1 );
		$ft_value   	= ( $ft_type == 5 ? 0 : 1 );
		
		$ft_maxcount	= ( $ft_type == 5 ? 0 : 90 );
		$ft_maxcount	= ( $ft_type == 3 ? 1 : $ft_maxcount );
		

		$fields 	= "ft_name			, ft_remark	, ft_multiple, ft_value,  ft_area	, ft_type 		,ft_maxcount	,ft_example, ft_scoop	";
		$values 	= "'{$new_feature}'	,'{$remark}',$ft_multiple,$ft_value,'$Area'		,{$ft_type}	,{$ft_maxcount},''			,7			";

		$prim_key 	= 'ft_id';
		
		$erg		=$sql_world->insert('feature',$fields,$values,$prim_key);
		
		if(!empty($sql_world->errnr)) $message[]='SQL ERROR: '.$sql_world->errstr;
	}
	else
	{
		$message[]= "<script language='JavaScript' type='text/javascript'>alert('Please enter a valid feature name and select an area');</script>";
	}
}

if($button=='Update')
{
	Do {
		$name=key($GLOBALS);
		if (substr($name,0,3) != 'FT_') continue;
		$ftvars[]=$name;
	}
	while ( next($GLOBALS));

	$query	="SELECT * FROM feature WHERE ft_area = '".$Area."'";
	$erg	=$sql_world->select($query,0,0);

 	for($i=0;$i<count($erg);$i++)
 	{
 		$ft_ids.=$erg[$i][0].',';
 	}

	$ft_ids = rchopright(',',$ft_ids);

	$delquery="DELETE FROM fto WHERE fto_ft_id IN ($ft_ids) AND fto_user_id = ".$user_id;

	$sql_world->exec($delquery);

	if($sql_world->errstr !='') {
		$message[]='SQL ERROR: '.$sql_world->errstr;
	}

	for($i=0; $i<count($ftvars); $i++)
	{
		for($j=0; $j<count($$ftvars[$i]); $j++)
		{
			$v=$$ftvars[$i];
			if($v[$j]!= '')
			{
				$values = sprintf("%s,%s,'%s'",$user_id,substr($ftvars[$i],3),$v[$j]);
				$fields = 'fto_user_id,fto_ft_id,fto_value';
				$sql_world->insert('fto',$fields,$values,'fto_id');
				if(!empty($sql_world->errnr)) $message[]='SQL ERROR: '.$sql_world->errstr;
			}
		}
	}
}

if (isset($new_area) && $new_area == 1)	unset ($Area);
if (!empty($message)) $GLOBALS['DC_ENV']->message = $message;

include 'newfeature.msk';

?>
Return current item: Netautor Professional