link($options); } else { $result = $this->dropdown($options); } return $result; } protected function getInfo($options) { if ($options['type'] == 'print') { $print = \Prints::get($options['id']); $result = [ 'link' => \Prints::getHref($options['id'], $options['id_record'], $options['parameters']), 'title' => tr('Stampa').' '.((strtoupper($print['title']) == $print['title']) ? $print['title'] : lcfirst($print['title'])), 'icon' => $print['icon'], ]; } else { $template = \Mail::getTemplate($options['id']); $result = [ 'link' => ROOTDIR.'/mail.php?id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id='.$options['id'], 'title' => tr('Invia').' '.((strtoupper($template['name']) == $template['name']) ? $template['name'] : lcfirst($template['name'])), 'icon' => $template['icon'], 'type' => 'modal', ]; } return $result; } protected function link($options) { $info = $this->getInfo($options); $class = isset($options['class']) ? $options['class'] : 'btn-info'; $class = !empty($class) ? ' class="btn '.$class.'" ' : ''; $title = isset($options['label']) ? $options['label'] : $info['title']; $icon = !empty($options['icon']) ? $options['icon'] : $info['icon']; $icon = str_replace('|default|', $info['icon'], $icon); // Modal if (isset($info['type']) && $info['type'] == 'modal') { $result = ' '; } // Link normale else { $result = ' '; } $result .= ' '.$title.' '; return $result; } protected function getList($options) { if ($options['type'] == 'print') { $results = \Prints::getModulePrints($options['id_module']); } else { $results = \Mail::getModuleTemplates($options['id_module']); } return $results; } protected function dropdown($options) { $list = $this->getList($options); $count = count($list); $options['class'] = isset($options['class']) ? $options['class'] : 'btn-info'; if ($count > 1) { $result = '
'; $predefined = array_search(1, array_column($list, 'predefined')); if ($predefined !== false) { $element = $list[$predefined]; $result .= $this->link([ 'type' => $options['type'], 'id' => $element['id'], 'id_module' => $options['id_module'], 'id_record' => $options['id_record'], 'class' => $options['class'], 'parameters' => $options['parameters'], ]); unset($list[$predefined]); } $result .= '
'; } elseif ($count == 1) { $result = $this->link([ 'type' => $options['type'], 'id' => $list[0]['id'], 'id_module' => $options['id_module'], 'id_record' => $options['id_record'], 'class' => $options['class'], 'parameters' => $options['parameters'], 'html_id' => $options['html_id'], ]); } else { $result = ' '; } return $result; } protected function defaultText($options) { if ($options['type'] == 'print') { $result = ' '.tr('Stampa'); } else { $result = ' '.tr('Invia'); } return $result; } }