Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > osTicket 1.6.x > Mods and Customizations

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-15-2012, 11:35 AM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default Checklists

EDIT: Go to post 7 for how I did this!!!!! Mostly....

I need a bit of help building a checklist system into my Staff Viewticket page. This is just for internal use so that we can tell where we are on certain repairs and what-not.
Unfortunately, like so many, I am not a programmer. Actually before OsTicket and this great forum (thanks by the way!) I had never coded anything more difficult than a batch file.

I have built the form with checkboxes, and found how to Implode the created array into a usable string. However thats where i faulter.
I have created 2 new "fields" mostly as described here:
http://osticket.com/forums/showthrea...ighlight=field
I have omitted a couple of places it was not needed, like new ticket creation.

1 field (malinfect) will be strickly an interger (although specified in the database as text, to mimick the other and allow for testing) and functions perfectly.
field 2 (clist) will contain the checklist data. Now the problem is assigning the imploded array to $tickets->getclist() to be updated in the database. Anytime i try, it only returns "clist" vs. 'HDD,antivir' as it is supposed to.

Here is the code i have so far for the form:
HTML Code:
<script type="text/javascript"> 
function toggle(chkbox, group) { 
    var visSetting = (chkbox.checked) ? "block" : "none"; 
    document.getElementById(group).style.display = visSetting; 
} 
</script>
<table>
	<tr><td>
			<b>Tune-Up</b>&nbsp;<input type="checkbox" name="list" value="Tune-Up" onclick="toggle(this,'tuneup')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<b>OS Load</b>&nbsp;<input type="checkbox" name="list" value="OS Load" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<b>Data Transfer</b>&nbsp;<input type="checkbox" name="list" value="Data Transfer" />
			  </tr></td>
	<tr><td><div  id="tuneup" style="display: none;">
		<form name="tunelist" action='tickets.php?id=<?=$id?>' method="post">
		<input type='hidden' name='a' value="update2"/>
	
		<br/><input type="checkbox" name="clista[]" value='HDD'>&nbsp;&nbsp;<b>HDD Diag</b><br/>
		<input type="checkbox" name="clista[]" value="antiv">&nbsp;&nbsp;<b>Check Anti-Virus</b><br/>
		<input type="checkbox" name="clista[]" value="excessprograms">&nbsp;&nbsp;<b>Remove Excess Programs</b><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="adobe">&nbsp;&nbsp;<b>Removed Adobe-Update</b><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="Java">&nbsp;&nbsp;<b>Removed Java-Update</b><br/>
		<input type="checkbox" name="clista[]" value="msconfig">&nbsp;&nbsp;<b>Disable Programs in MSCONFIG</b><br/>
		<input type="checkbox" name="clista[]" value="hiddenfiles">&nbsp;&nbsp;<b>Show Hidden Files</b><br/>
		<br/><b>Delete Temp Files</b><br/>
			&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="7vista" onclick="toggle(this,'7vista')">&nbsp;&nbsp;<b>Vista/7</b>
			&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="XP/9x" onclick="toggle(this,'XP')">&nbsp;&nbsp;<b>XP/9x</b><br/>
				<div id="7vista" style="display: none;">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Users\*user name*\appdata\local\temp</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Temp (if applicable)</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Windows\Temp</b><br/>
				</div>
				<div id="XP" style="display: none;">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Documents and Settings\*user name*\Local Settings\Temp</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Temp (if applicable)</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Windows\Temp</b><br/>
				</div>
		<br/><b>Delete Browser Data</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="IE">&nbsp;&nbsp;<b>Internet Explorer</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="Firefox">&nbsp;&nbsp;<b>Firefox</b><br/>	
		&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="Chrome">&nbsp;&nbsp;<b>Chrome</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clista[]" value="bother">&nbsp;&nbsp;<b>Other</b><br/>
		<br/><input type="checkbox" name="clista[]" value="winupdate">&nbsp;&nbsp;<b>Install Windows Updates</b><br/>
		<input type="checkbox" name="clista[]" value="install">&nbsp;&nbsp;<b>Install Anti-Virus/Java/Adobe/anything else</b><br/>
		<input type="checkbox" name="clista[]" value="malware">&nbsp;&nbsp;<b>Install & Run Anti-Malware</b>&nbsp;&nbsp;&nbsp;&nbsp;
			<b># of Infections</b><input type="text" size="3" name="malinfect" value=<?=($ticket->getmalinfect())?>><br/>
		<input type="checkbox" name="clista[]" value="restore">&nbsp;&nbsp;<b>Delete Restore Points</b><br/>
		<input type="checkbox" name="clista[]" value="recycle">&nbsp;&nbsp;<b>Empty Recycle Bin</b><br/>
		<input type="checkbox" name="clista[]" value="defrag">&nbsp;&nbsp;<b>Defrag</b><br/>
		<input type="checkbox" name="clista[]" value="winupdate">&nbsp;&nbsp;<b>Update Ticket With All Info!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</b><br/><br/>
		<input class="button" type="submit" value="Update">
		</div>
		</form>
	</tr></td>
</table>
(i realize i still have some stuff to clean up, but recommendations are accepted )

And this is the current state of my processing code:
PHP Code:
//We are ready baby...lets roll. Akon rocks! 
$dept  $ticket->getDept();  //Dept
$staff $ticket->getStaff(); //Assiged staff.
$lock  $ticket->getLock();  //Ticket lock obj
$sig   $ticket->getsig();  //capture signature
$id       $ticket->getId(); //Ticket ID.
$clist =& $ticket->getclist();


//$clist=$ticket->getclist(implode(",", $_POST['clista']));
if (isset($_POST['clista'])) 
{       
$clist implode(","$_POST['clista']);
}

var_dump($clist);
var_dump($ticket->getclist());
var_dump(implode(','$_POST['clista'])); 
I also had to create a new Function on class.ticket.php called update2 to get around the form trying to update everything else too. but that was just a copy/paste scenario with only these 2 fields left to update.

Now this is not complete (prolly not even right) and includes some stuff i tried to no avail.
right now i would be happy to get the data to the database, i can tackle exploding it after that (one step at a time )

If anybody knows a better way to get this data in the database (or the right way) let me know!
If you need more info, i'm happy to help you help me!

Last edited by jbartlett323; 04-03-2012 at 04:28 PM.
Reply With Quote
  #2  
Old 03-20-2012, 01:41 PM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default

Bump!!

69 views and no answers. Can somebody tell me that they don't know, at least??
Reply With Quote
  #3  
Old 03-21-2012, 09:11 AM
ksalisbury ksalisbury is offline
Junior Member
 
Join Date: Feb 2012
Location: RI
Posts: 8
Default

Quote:
Originally Posted by jbartlett323 View Post
Bump!!

69 views and no answers. Can somebody tell me that they don't know, at least??

Hey! I can do that! Wish I could help, but I'm a newbie at OSTicket and coding too. My last batch file was made to check machines for Y2k compliance.
Reply With Quote
  #4  
Old 03-21-2012, 03:47 PM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default

Quote:
Originally Posted by ksalisbury View Post
Hey! I can do that! Wish I could help, but I'm a newbie at OSTicket and coding too. My last batch file was made to check machines for Y2k compliance.
LOL, Thanks for the reply!
Yeah i know most on here are in the same boat, doesn't seem like too many coders on this board anymore. I would take it to a more code oriented site, but I don't want to have to write a 12 page dissertation to explain how osticket works and how what i'm trying to do is supposed to work in my mind....

Well the search continues!!! Any input is appreciated!! (yes, any input!! )
Reply With Quote
  #5  
Old 03-23-2012, 11:36 AM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default

ok, so every time i work on this I understand a bit more about osticket. this is a complex program for a newbie!! I love it!!

Anyway, I have found that when I created the 'update2' section in class.ticket.php (mentioned, however not expanded upon earlier) I removed a bit that wasn't supposed to come out in an attempt to get more than ' ' in my database. well it worked, kinda. I got 'clist' instead. just figured this out, so now i'm back to ' '. Heres the code if it helps anyone:

PHP Code:
function update($var,&$errors) {
         global 
$cfg,$thisuser;

         
$fields=array();
         
$fields['name']     = array('type'=>'string',   'required'=>1'error'=>'Name required');
         
$fields['email']    = array('type'=>'email',    'required'=>0'error'=>'Email is required');
         
$fields['bname']     = array('type'=>'string',   'required'=>0'error'=>'Business Name required'); //added field
         
$fields['address']    = array('type'=>'text',    'required'=>0'error'=>'Valid address required');  //added field
         
$fields['city']    = array('type'=>'text',    'required'=>0'error'=>'Valid city required');  //added field
         
$fields['state']    = array('type'=>'text',    'required'=>0'error'=>'Valid state required');  //added field
         
$fields['zip']    = array('type'=>'text',    'required'=>0'error'=>'Valid zip code required');  //added field
         
$fields['make']    = array('type'=>'text',    'required'=>0'error'=>'Please enter machine Brand');  //added field
         
$fields['model']    = array('type'=>'text',    'required'=>0'error'=>'Please enter machine model');  //added field
         
$fields['serial']    = array('type'=>'text',    'required'=>0'error'=>'Please enter machine Serial #');  //added field
         
$fields['OS']    = array('type'=>'text',    'required'=>0'error'=>'Please enter your Operating System');  //added field
         
$fields['pass']    = array('type'=>'text',    'required'=>0'error'=>'Enter your password');  //added field
         
$fields['sig']        = array('type'=>'text',    'required'=>0,  'error'=>'sign your name');  //added field
         
$fields['note']     = array('type'=>'text',     'required'=>0'error'=>'Reason for the update required');
         
$fields['subject']  = array('type'=>'string',   'required'=>1'error'=>'Subject required');
         
$fields['topicId']  = array('type'=>'int',      'required'=>0'error'=>'Invalid Selection');
         
$fields['pri']      = array('type'=>'int',      'required'=>0'error'=>'Invalid Priority');
         
$fields['phone']    = array('type'=>'phone',    'required'=>1'error'=>'Valid phone # required');
         
$fields['duedate']  = array('type'=>'date',     'required'=>0'error'=>'Invalid date - must be MM/DD/YY');

         
         
$params = new Validator($fields);
         if(!
$params->validate($var)){
             
$errors=array_merge($errors,$params->errors());
         }

         if(
$var['duedate']){
             if(
$this->isClosed())
                 
$errors['duedate']='Duedate can NOT be set on a closed ticket';
             elseif(!
$var['time'] || strpos($var['time'],':')===false)
                 
$errors['time']='Select time';
             elseif(
strtotime($var['duedate'].' '.$var['time'])===false)
                 
$errors['duedate']='Invalid duedate';
             elseif(
strtotime($var['duedate'].' '.$var['time'])<=time())
                 
$errors['duedate']='Due date must be in the future';
         }

        
//Make sure phone extension is valid
        
if($var['phone_ext'] ) {
            if(!
is_numeric($var['phone_ext']) && !$errors['phone'])
                
$errors['phone']='Invalid phone ext.';
            elseif(!
$var['phone']) //make sure they just didn't enter ext without phone #
                
$errors['phone']='Phone number required';
        }

        
$cleartopic=false;
        
$topicDesc='';
        if(
$var['topicId'] && ($topic= new Topic($var['topicId'])) && $topic->getId()) {
            
$topicDesc=$topic->getName();
        }elseif(!
$var['topicId'] && $this->getTopicId()){
            
$topicDesc='';
            
$cleartopic=true;
        }

 
         if(!
$errors){
             
$sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '.
                  
',email='.db_input($var['email']).
                  
',name='.db_input(Format::striptags($var['name'])).
                  
',bname='.db_input(Format::striptags($var['bname'])).  //added field
                  
',address='.db_input($var['address']).  //added field
                  
',city='.db_input($var['city']).  //added field
                  
',state='.db_input($var['state']).  //added field
                  
',zip='.db_input($var['zip']).  //added field
                  
',make='.db_input($var['make']).  //added field
                  
',model='.db_input($var['model']).  //added field
                  
',serial='.db_input($var['serial']).  //added field
                  
',OS='.db_input($var['OS']).  //added field
                  
',pass='.db_input($var['pass']).  //added field
                  
',sig='.db_input($var['sig']).  //added field
                  
',subject='.db_input(Format::striptags($var['subject'])).
                  
',phone="'.db_input($var['phone'],false).'"'.
                  
',phone_ext='.db_input($var['phone_ext']?$var['phone_ext']:NULL).
                  
',priority_id='.db_input($var['pri']).
                  
',topic_id='.db_input($var['topicId']).
                  
',duedate='.($var['duedate']?db_input(date('Y-m-d G:i',Misc::dbtime($var['duedate'].' '.$var['time']))):'NULL');
             if(
$var['duedate']) { //We are setting new duedate...
                 
$sql.=',isoverdue=0';
             }
             if(
$topicDesc || $cleartopic) { //we're overwriting previous topic.
                 
$sql.=',helptopic='.db_input($topicDesc);
             }
             
$sql.=' WHERE ticket_id='.db_input($this->getId());
             
//echo $sql;
             
if(db_query($sql)){
                 
//$this->postNote('Ticket Updated',$var['note']);
                 
$this->reload();
                 return 
true;
             }
         }

         return 
false;
    }
    
    function 
update2($var,&$errors) {
         global 
$cfg,$thisuser;

         
$fields=array();
         
$fields['malinfect'] = array('type'=>'text''required'=>0,  'error'=>'enter a number');  //added field
         
$fields['clist'] = array('type'=>'text''required'=>0,  'error'=>'check a box');  //added field
                  
         
$params = new Validator($fields);
         if(!
$params->validate($var)){
             
$errors=array_merge($errors,$params->errors());
         }

        
$cleartopic=false;
        
$topicDesc='';
        if(
$var['topicId'] && ($topic= new Topic($var['topicId'])) && $topic->getId()) {
            
$topicDesc=$topic->getName();
        }elseif(!
$var['topicId'] && $this->getTopicId()){
            
$topicDesc='';
            
$cleartopic=true;
        }

 
         if(!
$errors){
             
$sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '.
                  
',malinfect='.db_input($var['malinfect']).  //added field
                  
',clist='.db_input($var['clist']);  //added field
            
             
if($topicDesc || $cleartopic) { //we're overwriting previous topic.
                 
$sql.=',helptopic='.db_input($topicDesc);
             }
             
$sql.=' WHERE ticket_id='.db_input($this->getId());
             
//echo $sql;
             
if(db_query($sql)){
                 
//$this->postNote('Ticket Updated',$var['note']);
                 
$this->reload();
                 return 
true;
             }
         }

         return 
false;
    } 
I also included the original "update" function for reference (complete with all the other fields i have added successfully!)

I think this kinda points to my problem though... I think somewhere in osticket it is stripping stuff from the string before it hits the database. I understand there is a good reason for this behavior (sql injection attacks) but I gotta get around it.
So perhaps someone has had a similar problem of getting data to the database and they would share a work around? It would be greatly appreciated.

Also i searched before, and at least one other person wanted to do something similar. So if anything in here can help the community, i'm all about it! might try to make this a bit more reader friendly after I figure it out...
Reply With Quote
  #6  
Old 03-29-2012, 10:44 AM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default

ok, partly an update, partly a bump:

think i'm narrowing the issue...
If i put in just a standard text box, i can add to and edited the data in the clist field. I think this might point me to an issue: the implode is happening at the same time its trying to update the database with the imploded data, therefore only capturing a "" input cause it isn't done processing till after... I dont know... kinda grasping at straws...
Reply With Quote
  #7  
Old 04-03-2012, 04:26 PM
jbartlett323 jbartlett323 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 6
Default Solution!! mostly....

ok, so after trying this, that, and the other thing, i have figured out how this works!!!

Start with adding Variables as described in previous post, changing "type" to "text".

Build your checkbox form on the viewticket.inc.php page. I put mine right below the "action" section (where you close tickets and change priority etc.) and added a small piece of jscript to hide/show it. Heres mine for reference:

HTML Code:
<script type="text/javascript"> 
function toggle(chkbox, group) { 
    var visSetting = (chkbox.checked) ? "block" : "none"; 
    document.getElementById(group).style.display = visSetting; 
} 
</script>
<table id='checklists'>
	<tr><td>
			<b>Tune-Up</b>&nbsp;<input type="checkbox" name="list" value="Tune-Up" onclick="toggle(this,'tuneup')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<b>OS Load</b>&nbsp;<input type="checkbox" name="list" value="OS Load" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<b>Data Transfer</b>&nbsp;<input type="checkbox" name="list" value="Data Transfer" />
			  </tr></td>
	<tr><td><div  id="tuneup" style="display: none;">
		<form name="tunelist" action='tickets.php?id=<?=$id?>' method="post">
		<input type='hidden' name='a' value="clistimport"/>
		
		<br/><input type="checkbox" name='clist[]' value='hdd' <?php if($clist[] == 'hdd'){echo 'checked="checked"';}?>>&nbsp;&nbsp;<b>HDD Diag</b><br/>
		<input type="checkbox" name='clist[]' value='antiv' <?php if($clist[] == 'antiv'){echo 'checked="checked"';}?>>&nbsp;&nbsp;<b>Check Anti-Virus</b><br/>
		<input type="checkbox" name="clist[]" value="excessprograms">&nbsp;&nbsp;<b>Remove Excess Programs</b><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="adobe">&nbsp;&nbsp;<b>Removed Adobe-Update</b><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="Java">&nbsp;&nbsp;<b>Removed Java-Update</b><br/>
		<input type="checkbox" name="clist[]" value="msconfig">&nbsp;&nbsp;<b>Disable Programs in MSCONFIG</b><br/>
		<input type="checkbox" name="clist[]" value="hiddenfiles">&nbsp;&nbsp;<b>Show Hidden Files</b><br/>
		<br/><b>Delete Temp Files</b><br/>
			&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="7vista" onclick="toggle(this,'7vista')">&nbsp;&nbsp;<b>Vista/7</b>
			&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="XP/9x" onclick="toggle(this,'XP')">&nbsp;&nbsp;<b>XP/9x</b><br/>
				<div id="7vista" style="display: none;">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Users\*user name*\appdata\local\temp</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Temp (if applicable)</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="7 vista temp">&nbsp;&nbsp;<b>C:\Windows\Temp</b><br/>
				</div>
				<div id="XP" style="display: none;">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Documents and Settings\*user name*\Local Settings\Temp</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Temp (if applicable)</b><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="XP Temp">&nbsp;&nbsp;<b>C:\Windows\Temp</b><br/>
				</div>
		<br/><b>Delete Browser Data</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="IE">&nbsp;&nbsp;<b>Internet Explorer</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="Firefox">&nbsp;&nbsp;<b>Firefox</b><br/>	
		&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="Chrome">&nbsp;&nbsp;<b>Chrome</b><br/>
		&nbsp;&nbsp;<input type="checkbox" name="clist[]" value="bother">&nbsp;&nbsp;<b>Other</b><br/>
		<br/><input type="checkbox" name="clist[]" value="winupdate">&nbsp;&nbsp;<b>Install Windows Updates</b><br/>
		<input type="checkbox" name="clist[]" value="install">&nbsp;&nbsp;<b>Install Anti-Virus/Java/Adobe/anything else</b><br/>
		<input type="checkbox" name="clist[]" value="malware">&nbsp;&nbsp;<b>Install & Run Anti-Malware</b>&nbsp;&nbsp;&nbsp;&nbsp;
			<b># of Infections</b><input type="text" size="3" name="malinfect" value=<?=($ticket->getmalinfect())?>><br/>
		<input type="checkbox" name="clist[]" value="restore">&nbsp;&nbsp;<b>Delete Restore Points</b><br/>
		<input type="checkbox" name="clist[]" value="recycle">&nbsp;&nbsp;<b>Empty Recycle Bin</b><br/>
		<input type="checkbox" name="clist[]" value="defrag">&nbsp;&nbsp;<b>Defrag</b><br/>
		<input type="checkbox" name="clist[]" value="winupdate">&nbsp;&nbsp;<b>Update Ticket With All Info!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</b><br/><br/>
		<input class="button" type="submit" value="Update">
		</div>
		</form>
	</tr></td>
</table>
Ok, now the fun begins:
To get the data to the database, we must first Implode the clist[] array to a single string. to do this, i found that i had to create a new function to handle this then pass to a modified "update" function.
So on the scp/tickets.php i added this:
PHP Code:
case 'clistimport':
            
$_POST['clist']=implode(","$_POST['clist']);
            
$ticket->update2($_POST,$errors);  //lots of nifty new stuff in this and update2 section!
            
break;
        case 
'update2':
            if(!
$ticket || !$thisuser->canEditTickets())
                
$errors['err']='Perm. Denied. You are not allowed to edit tickets';
            elseif(
$ticket->update2($_POST,$errors)){
                
$msg='Ticket updated successfully';
                
$page='viewticket.inc.php';
            }elseif(!
$errors['err']) {
                
$errors['err']='Error(s) occured! Try again.';
            }
            break; 
Sorry, I'm not giving line numbers cause they wont match! But this goes right after the 'update' section, just search its the only one...

This bit of code tells it first to implode, then continue to 'update2' (which is nearly identical to 'update', however i removed the line about 'editticket.inc.php' so it doesn't try to update everything!).
'Update2' (just like 'update') sends this info to the class.ticket.php function 'update2'!

So on class.ticket.php (where you added most of the variable stuff) you need to copy 'function update' and create 'function update2' which should look like this:
PHP Code:
function update2($var,&$errors) {
         global 
$cfg,$thisuser;

         
$fields=array();
         
$fields['malinfect'] = array('type'=>'text''required'=>0,  'error'=>'enter a number');  //added field
         
$fields['clist'] = array('type'=>'text''required'=>0,  'error'=>'check a box');  //added field
                  
         
$params = new Validator($fields);
         if(!
$params->validate($var)){
             
$errors=array_merge($errors,$params->errors());
         }

        
$cleartopic=false;
        
$topicDesc='';
        if(
$var['topicId'] && ($topic= new Topic($var['topicId'])) && $topic->getId()) {
            
$topicDesc=$topic->getName();
        }elseif(!
$var['topicId'] && $this->getTopicId()){
            
$topicDesc='';
            
$cleartopic=true;
        }

 
         if(!
$errors){
             
$sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '.
                  
',malinfect='.db_input($var['malinfect']).  //added field
                  
',clist='.db_input($var['clist']);  //added field
            
             
if($topicDesc || $cleartopic) { //we're overwriting previous topic.
                 
$sql.=',helptopic='.db_input($topicDesc);
             }
             
$sql.=' WHERE ticket_id='.db_input($this->getId());
             
//echo $sql;
             
if(db_query($sql)){
                 
//$this->postNote('Ticket Updated',$var['note']);
                 
$this->reload();
                 return 
true;
             }
         }

         return 
false;
    } 
Now the only real difference is obviously what variables i'm updating, again i dont want to update everything!

Ok, so provided you created a column in your ost_ticket database called clist (or your variable name) with default values and "Text" type, this should work... maybe!


To get the data back from the database is significantly easier...
all you need to do on you viewticket.inc.php page is add the variable:
$clist = explode(',',$ticket->getclist());
Now you data will come back!

However this is where i once again run into problems: to get my checkboxes to check, the array has to be in the correct order. so i need to make sure that all checkboxes have a values to put in the database. I have looked at for, foreach, and other loops, but i dont know how to use them and deciphering them is tough when trying to apply it to this complex code... Anybody know the easiest way for me to do what i want? If not i'll post it when i figure it out....

EDIT: Ah! I got it! just add:
PHP Code:
<?php if(in_array('checkbox var here',$clist,TRUE)){echo 'checked="checked"';}?>
to each checkbox and name it to the same variable as the check box!
Hope this helps someone in the future!

Last edited by jbartlett323; 04-03-2012 at 05:41 PM.
Reply With Quote


Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:31 PM.