Esempio n. 1
0
 function TestRef()
 {
     $format = JRequest::getVar('ref');
     $ref = FSF_Ticket_Helper::createRef(1234, $format);
     echo $ref;
     exit;
 }
Esempio n. 2
0
 static function createRef($ticketid, $format = "", $depth = 0)
 {
     if ($format == "") {
         $format = FSF_Settings::get('support_reference');
     }
     if ($depth > 4) {
         $format = "4L-4L-4L";
     }
     preg_match_all("/(\\d[LNX])/i", $format, $out);
     if (strpos($format, "{") !== false) {
         preg_match_all("/{([A-Za-z0-9]+)}/i", $format, $out);
         $key = $format;
         foreach ($out[1] as $match) {
             $count = substr($match, 0, 1);
             $type = strtoupper(substr($match, 1, 1));
             if ($type == "" && (int) $count < 1) {
                 $type = $count;
                 $count = 1;
             }
             $replace = "";
             if ($type == "X") {
                 $replace = sprintf("%0" . $count . "d", $ticketid);
             } else {
                 if ($type == "N") {
                     for ($i = 0; $i < $count; $i++) {
                         $replace .= rand(0, 9);
                     }
                 } else {
                     if ($type == "L") {
                         for ($i = 0; $i < $count; $i++) {
                             $replace .= chr(rand(0, 25) + ord('A'));
                         }
                     } else {
                         if ($type == "D") {
                             $replace = date("Y-m-d");
                         }
                     }
                 }
             }
             $pos = strpos($key, "{" . $match . "}");
             if ($pos !== false) {
                 $key = substr($key, 0, $pos) . $replace . substr($key, $pos + strlen($match) + 2);
             }
         }
     } elseif (count($out) > 0) {
         $key = $format;
         foreach ($out[0] as $match) {
             $count = substr($match, 0, 1);
             $type = strtoupper(substr($match, 1, 1));
             $replace = "";
             if ($type == "X") {
                 $replace = sprintf("%0" . $count . "d", $ticketid);
             } else {
                 if ($type == "N") {
                     for ($i = 0; $i < $count; $i++) {
                         $replace .= rand(0, 9);
                     }
                 } else {
                     if ($type == "L") {
                         for ($i = 0; $i < $count; $i++) {
                             $replace .= chr(rand(0, 25) + ord('A'));
                         }
                     }
                 }
             }
             $pos = strpos($key, $match);
             if ($pos !== false) {
                 $key = substr($key, 0, $pos) . $replace . substr($key, $pos + strlen($match));
             }
         }
     } else {
         $key = FSF_Ticket_Helper::createRef($ticketid, "4L-4L-4L", $depth + 1);
     }
     $db = JFactory::getDBO();
     $query = "SELECT id FROM #__fsf_ticket_ticket WHERE reference = '" . FSFJ3Helper::getEscaped($db, $key) . "'";
     $db->setQuery($query);
     $rows = $db->loadAssoc();
     if ($rows) {
         $key = FSF_Ticket_Helper::createRef($ticketid, $format, $depth + 1);
     }
     return $key;
 }