SimpleDesk

SimpleDesk! => SimpleDesk Support => Topic started by: cristianlf on January 14, 2011, 09:49:47 PM

Title: Insert user fields
Post by: cristianlf on January 14, 2011, 09:49:47 PM
Hello friends,
I have a trouble in the office, my boss wants to add some fields to the ticket form and I added (at display level) but when I try to post the ticket i dont know how to add my fields into the insert function ??

I  mean I already add fields and tables to the Database, and just need to add some fields to the insert of new Tickets
well if you can help me pleaaase, this has to be done to monday :S

by the way i want to ask where is $context[] defined ??

regards
Title: Re: Insert user fields
Post by: Spoogs on January 14, 2011, 09:54:43 PM
One of the devs maybe able to help you with this... in the mean time I'd like to point out that custom fields are 1 of the features that will be rolled out with the 1.1 release.
Title: Re: Insert user fields
Post by: Francis on January 15, 2011, 12:31:25 AM
Hi,

Inserting of the tickets is done in Sources\SimpleDesk-Post.php. The very first function contains the parameters to insert in the database, if I remember correctly. $context is defined there as well.
Title: Re: Insert user fields
Post by: chilly on January 15, 2011, 05:39:58 AM
$context[] it a variable created by smf with global use through all of smf's code. (if that was the question)
Title: Re: Insert user fields
Post by: cristianlf on January 15, 2011, 10:46:30 AM
Thaks but the answers,

i will see Sources\SimpleDesk-Post.php

i will comment in a short time ...

regards,

Title: Re: Insert user fields
Post by: cσσкιє мσηѕтєя on January 15, 2011, 10:50:53 AM
The files you'll need to look in are:

SimpleDesk-Post.php
Subs-SimpleDesk-Post.php
SimpleDesk-Display.php
SimpleDesk-Display.template.php
SimpleDesk-Post.template.php
Title: Re: Insert user fields
Post by: cristianlf on January 15, 2011, 10:54:21 AM
Quote from: cσσкιє мσηѕтєя on January 15, 2011, 10:50:53 AM
The files you'll need to look in are:

SimpleDesk-Post.php
Subs-SimpleDesk-Post.php
SimpleDesk-Display.php
SimpleDesk-Display.template.php
SimpleDesk-Post.template.php

Thanks :)  i will let you know
Title: Re: Insert user fields
Post by: Gruffen on January 16, 2011, 06:04:39 AM
There's also 6 separate functions you'll have to modify, which is basically every place that $context['ticket_form'] is created.
Title: Re: Insert user fields
Post by: Francis on January 16, 2011, 11:04:51 AM
Quote from: Gruffen on January 16, 2011, 06:04:39 AM
There's also 6 separate functions you'll have to modify, which is basically every place that $context['ticket_form'] is created.
Well actually, these functions are in the files listed above by Cookie Monster.
Title: Re: Insert user fields
Post by: cristianlf on January 16, 2011, 03:07:17 PM
Thanks for the help, 

I need to add my variables in here

   $context['ticket_form'] = array( // yes, everything goes in here.
      'form_title' => $new_ticket ? $txt['shd_create_ticket'] : $txt['shd_edit_ticket'],
      'form_action' => $scripturl . '?action=helpdesk;sa=saveticket',
      'first_msg' => $new_ticket ? 0 : $ticketinfo['id_first_msg'],
      'message' => $new_ticket ? '' : $ticketinfo['body'],
      'subject' => $new_ticket ? '' : $ticketinfo['subject'],
      'ticket' => $new_ticket ? 0 : $context['ticket_id'],
      'link' => $new_ticket ? 0 : '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>',
      'msg' => $new_ticket ? 0 : $ticketinfo['id_first_msg'],
      'display_id' => $new_ticket ? '' : str_pad($context['ticket_id'], 5, '0', STR_PAD_LEFT),
      'status' => $new_ticket ? TICKET_STATUS_NEW : $ticketinfo['status'],
      'urgency' => array(
         'setting' => $new_ticket ? TICKET_URGENCY_LOW : $ticketinfo['urgency'],
      ),
      'private' => array(
         'setting' => $new_ticket ? false : ($ticketinfo['private'] == 1),
         'can_change' => shd_allowed_to('shd_alter_privacy_any') || (shd_allowed_to('shd_alter_privacy_own') && ($new_ticket || !empty($ticketinfo['is_own']))),
         'options' => array(
            0 => 'shd_ticket_notprivate',
            1 => 'shd_ticket_private',
         ),
      ),
      'errors' => array(),
      'num_replies' => $new_ticket ? 0 : $ticketinfo['num_replies'],
      'do_attach' => shd_allowed_to('shd_post_attachment'),
      'num_allowed_attachments' => empty($modSettings['attachmentNumPerPostLimit']) || $modSettings['shd_attachments_mode'] == 'ticket' ? -1 : $modSettings['attachmentNumPerPostLimit'],
      'return_to_ticket' => isset($_REQUEST['goback']),
      'disable_smileys' => $new_ticket ? !empty($_REQUEST['no_smileys']) : ($ticketinfo['smileys_enabled'] == 0),
   );


is correct?

but then I need to add and something to  ->  $ticketinfo
$newticket ? 0 : $ticket['myvariables']   

then I was seeing the $smcFunc['db_query']($identifier, $db_string, $db_values, $connection) but i dont get it quite well.

I was tryng (just as a debugging) to get the variables i made with $_REQUEST['myvariables'] bt I cant write the result using javacript alert  ....   

I ll keep trying doing the way you are sugesting, please if you could give me some more guidline .... 

Regards
Title: Re: Insert user fields
Post by: Francis on January 16, 2011, 08:33:23 PM
Use PHP to do:
<?php echo '<script type="text/javascript">alert("' . $_REQUEST['myvariables'] . '");<script>'; ?>
Or maybe -
<?php echo '<script type="text/javascript">alert("' . print_r($_REQUEST) . '");<script>'; ?>

I don't get what fields you want to add, what would they be?
Title: Re: Insert user fields
Post by: cristianlf on January 16, 2011, 11:25:31 PM
well i need to add 5 fields, that will be related and the user need to select, besides the  options will be store in the DB ... 

Title: Re: Insert user fields
Post by: cristianlf on January 17, 2011, 01:33:36 AM
Hello guys!!

Well I reaaly try to use shd_ functions to insert the data but ... 

I finaly do this .:

@ SimpleDesk-Post.php
     @shd_save_ticket()
                                        $context['Name_group_own_variables'] = array(
                                          'Variable 1' =>  $_POST['variable1'],
                                          'Variable 2' =>  $_POST['variable2']
                                          );

then
@ Subs-SimpleDeskPost.php
       @ shd_create_ticket_post
                          After if (empty($ticketOptions['id'])) {...}   I add te code:
                           else {
                                     $update ="update ....  ".
                                     "where id_ticket =".$ticketOptions['id'];
                           }
             

I know this is not the best way to do that  if you help me to get it better i'll apreciate it ,  I still need to display the values when someone see the ticket ... 

Well this was dificult to me, thanks every1 that helps me  someway ...

Regards
Title: Re: Insert user fields
Post by: Gruffen on January 18, 2011, 07:05:13 AM
Quote from: Francis on January 16, 2011, 11:04:51 AM
Quote from: Gruffen on January 16, 2011, 06:04:39 AM
There's also 6 separate functions you'll have to modify, which is basically every place that $context['ticket_form'] is created.
Well actually, these functions are in the files listed above by Cookie Monster.

Yes, I know that ;)

Putting it in shd_save_ticket() will make sure it's saved only when the ticket is edited or newly created (as opposed to on reply).

I would tried to help more but I can't help without knowing what fields you were trying to add, where you were trying to add them, etc. and the result is that it might well be a mess and/or do something unexpected... :/
Title: Re: Insert user fields
Post by: cristianlf on January 18, 2011, 10:24:17 AM
No worries ...

I was trying to add 5  <selects>  that are dependant ... so I had to insert an js file in the header a then change the functions that I explained before,

well I just need to add now a validation because the fields are not optional,  and I still working on that ... if you have some sugestions please tell me about it :)

Regards
Title: Re: Insert user fields
Post by: Gruffen on January 18, 2011, 05:44:58 PM
Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.
Title: Re: Insert user fields
Post by: cristianlf on January 18, 2011, 08:50:31 PM
Quote from: Gruffen on January 18, 2011, 05:44:58 PM
Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.

Thanks for the answer,  I did before you answer but I apreciate your help,  i do something like this:
@SimpleDesk-Post.php
   @shd_save_ticket


if (!isset($_POST['myvariable']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['myvariable'])) === ''
   ||$_POST['producto']=="..." )  // this is because my variables ...
   {
      $context['shd_errors'][] = 'no_myvariable';   // this is the name of the error
      $_POST['myvariable'] = '';
   }

then

@Error.english.php
$txt['no_myvariable']     = 'My Error Message ...';//'';


and then everithing works like a charm :) 


Wel Im traying to write all I done because maybe later I will need it again or  maybe help to someone else.

by the way Im trying to add some function to the text area, I need to limit to a #  and nee to display how characters are remaining,  Im stuck with the display  the remaining chars ... if someone could help  pleaase  !!!


Regards,
Title: Re: Insert user fields
Post by: Francis on January 19, 2011, 12:45:16 AM
Quote from: cristianlf on January 18, 2011, 08:50:31 PM
Quote from: Gruffen on January 18, 2011, 05:44:58 PM
Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.

Thanks for the answer,  I did before you answer but I apreciate your help,  i do something like this:
@SimpleDesk-Post.php
   @shd_save_ticket


if (!isset($_POST['myvariable']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['myvariable'])) === ''
   ||$_POST['producto']=="..." )  // this is because my variables ...
   {
      $context['shd_errors'][] = 'no_myvariable';   // this is the name of the error
      $_POST['myvariable'] = '';
   }

then

@Error.english.php
$txt['no_myvariable']     = 'My Error Message ...';//'';


and then everithing works like a charm :) 


Wel Im traying to write all I done because maybe later I will need it again or  maybe help to someone else.

by the way Im trying to add some function to the text area, I need to limit to a #  and nee to display how characters are remaining,  Im stuck with the display  the remaining chars ... if someone could help  pleaase  !!!


Regards,
Displaying the remaining characters can be done with Javascript. Just Google for a characters countdown. :)
Title: Re: Insert user fields
Post by: Gruffen on January 19, 2011, 07:39:38 AM
Unfortunately it's not as simple as that. That's only a valid solution when WYSIWYG is firmly disabled; if it's not... the textbox will be empty the whole time and the content managed through editing an iframe, which is substituted with the form values at submission.
Title: Re: Insert user fields
Post by: cristianlf on January 19, 2011, 12:21:17 PM
Well my Friends, I want to share that I did it :)
but I have a Question about  this  function:  "storeCaret(this);"

I don't know what is the purpose of that function so I just erase it ;)

My javascript knowledge is not that good, so Im going to explain what i did maybe some one could help me to improve it :)

First:
@GenericControls.template.php
   @template_control_richedit

before <textarea class ...
add this
<label id="Caracteres">250 caracteres restantes</label><br/>

In texarea tag
change onkeyup="storeCaret(this);"
for this:  onkeyup="showCar(this.value)"

then add maxlength="250"   //the number of characters you want ...

then I review the textarea id to insert it to my javascript ....
/***************JAVASCRIPT***********************/
var xmlHttp

function showCar(str)
{
   alert (str);
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
   {
      alert ("Browser does not support HTTP Request")
      return
   }
   var textarea =document.getElementById('shd_message')
   var largomaximo =textarea.getAttribute('maxlength')
   
   var url= "http://mysite/Sources/count.php" //"count.php"
   url=url+"?q="+str+"&lm="+largomaximo
   xmlHttp.onreadystatechange=stateChangedChar
   xmlHttp.open("GET",url,true)
   xmlHttp.send(null)
//   alert (str.length+1)
}

function stateChangedChar()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
      var label = document.getElementById('Caracteres')
      label.innerHTML =xmlHttp.responseText
   }
}

function GetXmlHttpObject()
{
   var xmlHttp=null;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      //Internet Explorer
      try
        {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
   }
   return xmlHttp;
}
/***************JAVASCRIPT***********************/

As you see I use count.php  but this is the part  i want to remove but i do not know how ?_? 

this is count.php

/**********count.php*******************/
<?
   $q=$_REQUEST['q'];
   $lm=$_REQUEST['lm'];
   $resta =$lm-strlen($q);
   if ($resta>1)
      $leyenda =" caracteres restantes";
   elseif ($resta==1)
      $leyenda=" caracter restante";
   else
      $leyenda =" caracteres restantes";
   
   echo $resta.$leyenda;
?>

well If there are somethig you can recomend to me please do,

Regards

Title: Re: Insert user fields
Post by: Gruffen on January 19, 2011, 01:06:03 PM
storeCaret is used by SMF quite a bit, specifically in IE it deals with handling the cursor for the purposes of adding bbcode from buttons as well as smileys... so if you removed it, it's now going to be broken.

:o

Let me explain the problem with that. For every single keypress a user makes in your textbox, that's going to generate a full roundtrip to your server.

Just writing the above, I would have generated 370 requests on your server. 370 connections, 370 page loads. It will overload your server to keep doing that!

You could have gotten the length of content without a server roundtrip but that still wouldn't solve the issue of the fact that neither what I was talking about or the above will work with WYSIWYG which will always report a length of 0 characters.

Why it is so important to keep it within 250 characters? Given that the first three paragraphs I wrote (everything before the 'Just writing the above') is over 50% larger than your 250 character limit, and that there is almost no performance difference between using 250 characters and 25000 in a ticket post, I really have to wonder what the benefit of limiting user post size is?
Title: Re: Insert user fields
Post by: cristianlf on January 19, 2011, 02:58:01 PM
thanks for your answer,

Well I think that way, but my boss want to limit to 250 because is a way to make users write the main problem withouth unimportant details,
Besides I disable bbc and html editing I need just plain text ... 

if you can help me with the javascript part to be more eficient pleaaase do,

thanks :)

I will try to do it without calling a php file ... do not how but i will :)

Regards,
Title: Re: Insert user fields
Post by: cristianlf on January 19, 2011, 04:32:17 PM
Ok I did it I erase de PHP file ... this is my function now :)


function showCar(str)
{
   
   
   var textarea =document.getElementById('shd_message')
   var largomaximo =textarea.getAttribute('maxlength')
   var texto =""
   var label = document.getElementById('Caracteres')
      texto =largomaximo-str.length
      var leyenda =" Caracteres Restantes"
      if (texto == 1)
      {
         leyenda =" Caracter Restante"
      }
      label.innerHTML =texto + leyenda
}


Title: Re: Insert user fields
Post by: Francis on January 19, 2011, 06:06:22 PM
To be honest I would of simply limited the database field to 250 and edited the string for Description to Description (250 characters max.).
Title: Re: Insert user fields
Post by: Gruffen on January 20, 2011, 02:16:43 PM
If you've disabled WYSIWYG the above function should be fine.

But really 250 characters is not even 2 text messages... it's useless for providing any actual detail and it'll annoy your users more than it'll help your boss because all that'll happen is users either won't use it, or they'll make multiple posts up to get their information across.

(I can't honestly believe too *much* detail is a problem. Too *little* is always more a problem and making it 250 characters encourages them to leave out useful details!)
Title: Re: Insert user fields
Post by: Gruffen on April 11, 2011, 06:38:33 AM
Fortunately we tackled this in the custom fields implementation; you can set a maximum size on things but otherwise it's 64K characters in length.