public function handleTask(&$context)
 {
     /* Insert here source code to execute the task */
     $adb = PearDatabase::getInstance();
     $serie = $this->get('serie');
     $adb->query('LOCK TABLES vtiger_wf_customnumbering WRITE', false);
     $sql = 'SELECT * FROM vtiger_wf_customnumbering WHERE serie = ?';
     $result = $adb->pquery($sql, array($serie), false);
     if ($adb->num_rows($result) == 0) {
         $sql = 'INSERT INTO vtiger_wf_customnumbering SET `serie` = ?, `prefix` = ?, `current` = ?, `length` = ?';
         $adb->pquery($sql, array($serie, $this->get('serie_prefix'), intval($this->get('serie_start')) + 1, $this->get('serie_length')));
         $nextId = $this->get('serie_start');
     } else {
         $nextId = $adb->query_result($result, 0, 'current');
         $adb->pquery('UPDATE vtiger_wf_customnumbering SET current = current + 1 WHERE serie = ?', array($serie));
     }
     $adb->query('UNLOCK TABLES', false);
     $IDString = $this->get('serie_prefix') . str_pad($nextId, $this->get('serie_length'), '0', STR_PAD_LEFT);
     $fieldInfo = \Workflow\VtUtils::getFieldInfo($this->get('field'), getTabid($this->getModuleName()));
     $context->set($this->get('field'), $IDString);
     $sql = 'UPDATE ' . $fieldInfo['tablename'] . ' SET `' . $fieldInfo['columnname'] . '` = ? WHERE `' . $this->get('crmidCol') . '` = ?';
     $adb->pquery($sql, array($IDString, $context->getId()));
     return "yes";
 }
 function wf_fieldlabel($module, $fieldName)
 {
     if (!is_array($fieldName)) {
         $fieldName = array($fieldName);
         $single = true;
     } else {
         $single = false;
     }
     $tabid = getTabid($module);
     foreach ($fieldName as $field) {
         if ($field == 'crmid') {
             $fieldLabel = 'CRMID';
         } else {
             $fieldInfo = \Workflow\VtUtils::getFieldInfo($field, $tabid);
             $fieldLabel = $fieldInfo['fieldlabel'];
         }
         if (empty($fieldLabel)) {
             $fieldLabel = $field;
         }
         $return[] = $fieldLabel;
     }
     if ($single === true) {
         return $return[0];
     } else {
         return $return;
     }
 }