Exemple #1
0
 /**
  * Extends the Media constructor.
  * Create a certificate from the file path
  * @param string $data
  * @param Tree $tree Reference tree
  * @param CertificateProviderInterface $provider
  */
 public function __construct($data, Tree $tree, CertificateProviderInterface $provider)
 {
     $this->provider = $provider;
     // Data is only the file name
     $data = str_replace("\\", '/', $data);
     $xref = Functions::encryptToSafeBase64($data);
     $gedcom = sprintf('0 @%1$s@ OBJE' . PHP_EOL . '1 FILE %2$s', $xref, $data);
     parent::__construct($xref, $gedcom, '', $tree);
     $this->title = basename($this->getFilename(), '.' . $this->extension());
     $match = null;
     $ct = preg_match("/(?<year>\\d{1,4})(\\.(?<month>\\d{1,2}))?(\\.(?<day>\\d{1,2}))?( (?<type>[A-Z]{1,2}) )?(?<details>.*)/", $this->title, $match);
     if ($ct > 0) {
         $monthId = (int) $match['month'];
         $calendarShortMonths = Functions::getCalendarShortMonths();
         $monthShortName = array_key_exists($monthId, $calendarShortMonths) ? $calendarShortMonths[$monthId] : $monthId;
         $this->certDate = new Date($match['day'] . ' ' . strtoupper($monthShortName) . ' ' . $match['year']);
         $this->certType = $match['type'];
         $this->certDetails = $match['details'];
     } else {
         $this->certDetails = $this->title;
     }
 }
    /**
     * Certificate@index
     */
    public function index()
    {
        global $WT_TREE;
        $controller = new PageController();
        $controller->setPageTitle(I18N::translate('Certificate'))->restrictAccess($this->module->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($WT_TREE));
        $cid = Filter::get('cid');
        $certificate = null;
        if (!empty($cid) && strlen($cid) > 22) {
            $certificate = Certificate::getInstance($cid, $WT_TREE, null, $this->provider);
        }
        $data = new ViewBag();
        $data->set('title', $controller->getPageTitle());
        $data->set('has_certif', false);
        if ($certificate) {
            $controller->restrictAccess($certificate->canShow());
            $data->set('title', $certificate->getTitle());
            $data->set('has_certif', true);
            $data->set('certificate', $certificate);
            $data->set('url_certif_city', 'module.php?mod=' . Constants::MODULE_MAJ_CERTIF_NAME . '&mod_action=Certificate@listAll' . '&ged=' . $WT_TREE->getNameUrl() . '&city=' . Functions::encryptToSafeBase64($certificate->getCity()));
            $controller->addInlineJavascript('
                jQuery("#certificate-tabs").tabs();
			    jQuery("#certificate-tabs").css("visibility", "visible");    
            ');
            $data->set('has_linked_indis', false);
            $data->set('has_linked_fams', false);
            $linked_indis = $certificate->linkedIndividuals();
            $linked_fams = $certificate->linkedFamilies();
            if ($linked_indis && count($linked_indis) > 0) {
                $data->set('has_linked_indis', true);
                $data->set('linked_indis', $linked_indis);
            }
            if (!empty($linked_fams)) {
                $data->set('has_linked_fams', true);
                $data->set('linked_fams', $linked_fams);
            }
        }
        ViewFactory::make('Certificate', $this, $controller, $data)->render();
    }
    /**
     * {@inhericDoc}
     * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
     */
    protected function renderContent()
    {
        $cities = $this->data->get('cities');
        $selected_city = $this->data->get('selected_city');
        ?>
                
        <div id="maj-cert-list-page" class="center">
			<h2><?php 
        echo $this->data->get('title');
        ?>
</h2>
			
			<form method="get" name="selcity" action="module.php">
    			<input type="hidden" name="mod" value="<?php 
        echo $this->data->get('url_module');
        ?>
">
    			<input type="hidden" name="mod_action" value="<?php 
        echo $this->data->get('url_action');
        ?>
">
    			<input type="hidden" name="ged" value="<?php 
        echo $this->data->get('url_ged');
        ?>
">
    			<select name="city">
    			<?php 
        foreach ($cities as $city) {
            ?>
    				<option value="<?php 
            echo Functions::encryptToSafeBase64($city);
            ?>
" <?php 
            if (trim($city) == trim($selected_city)) {
                echo 'selected="selected"';
            }
            ?>
 ><?php 
            echo $city;
            ?>
</option>
    			<?php 
        }
        ?>
    			</select>
    			<input type="submit" value="<?php 
        echo I18N::translate('Show');
        ?>
" />
    		</form>
    		
    		<?php 
        if ($this->data->get('has_list', false)) {
            ?>
    		<div class="loading-image">&nbsp;</div>
    		<div class="certificate-list">
    			<table id="<?php 
            echo $this->data->get('table_id');
            ?>
">
    				<thead>
    					<tr>
    						<th><?php 
            echo I18N::translate('Date');
            ?>
</th>
    						<th>datesort</th>
    						<th><?php 
            echo I18N::translate('Type');
            ?>
</th>
    						<th>certificatesort</th>
    						<th><?php 
            echo I18N::translate('Certificate');
            ?>
</th>
    					</tr>
    				</thead>
    				<tbody>
    				<?php 
            foreach ($this->data->get('certificate_list') as $certificate) {
                /** @var \MyArtJaub\Webtrees\Module\Certificates\Model\Certificate $certificate */
                ?>
    					<tr>
    						<!-- Certificate date -->
    						<?php 
                if ($date = $certificate->getCertificateDate()) {
                    ?>
    						<td><?php 
                    echo $date->display();
                    ?>
</td>
    						<td><?php 
                    echo $date->julianDay();
                    ?>
</td>
    						<?php 
                } else {
                    ?>
    						<td>&nbsp;</td>
    						<td>0</td>
    						<?php 
                }
                ?>
    						<!--  Certificate Type -->
    						<td><?php 
                echo Filter::escapeHtml($certificate->getCertificateType() ?: '');
                ?>
</td>
    						<!--  Certificate Name -->
    						<?php 
                $name = $certificate->getCertificateDetails() ?: '';
                $sortname = "";
                $ct_names = preg_match("/([A-Z]{2,})/", $name, $match);
                if ($ct_names > 0) {
                    $sortname = $match[1] . '_';
                }
                $sortname .= $name;
                ?>
    						<td><?php 
                echo Filter::escapeHtml($sortname);
                ?>
</td>
    						<td>
    							<a href="<?php 
                echo $certificate->getHtmlUrl();
                ?>
"><?php 
                echo Filter::escapeHtml($name);
                ?>
</a>
    						</td>
    					</tr>
    				<?php 
            }
            ?>
    				</tbody>
    			</table>
    		</div>    		
    		<?php 
        }
        ?>
    	</div>
    	
    	<?php 
    }