public static function renderControlSelectAllAuthoritativePlants($default_selected = 0)
 {
     if (is_object($default_selected)) {
         $default_selected = $default_selected->authoritative_plant_id;
     }
     global $DB;
     $all_ap = Authoritative_Plant::getAllFromDb(['flag_active' => true, 'flag_delete' => FALSE], $DB);
     usort($all_ap, 'Authoritative_Plant::cmp');
     $rendered = '<select name="authoritative_plant_id" id="authoritative-plant-id">' . "\n";
     foreach ($all_ap as $ap) {
         $rendered .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == $default_selected) . "\n";
     }
     $rendered .= '</select>';
     return $rendered;
 }
 function testRenderControlSelectAllAuthoritativePlants()
 {
     $aps = Authoritative_Plant::getAllFromDb(['flag_active' => true, 'flag_delete' => false], $this->DB);
     usort($aps, 'Authoritative_Plant::cmp');
     $canonical_base = '<select name="authoritative_plant_id" id="authoritative-plant-id">' . "\n";
     global $DB;
     $DB = $this->DB;
     //-------
     // no default select
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption() . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants();
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
     //-------
     // default select using an id number
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == 5005) . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants(5005);
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
     //-------------
     // default select using an object
     $default_ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5003], $this->DB);
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == $default_ap->authoritative_plant_id) . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants($default_ap);
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
 }
    }
    $action = 'view';
}
if ($action == 'list') {
    echo '<h2>' . ucfirst(util_lang('authoritative_plants')) . '</h2>' . "\n";
    if ($USER->canActOnTarget($ACTIONS['edit'], $ap)) {
        ?>
            <a href="<?php 
        echo APP_ROOT_PATH . '/app_code/authoritative_plant.php?action=create&user_id=' . $USER->user_id;
        ?>
" class="btn" id="btn-add-authoritative_plant"><?php 
        echo util_lang('add_authoritative_plant');
        ?>
</a><?php 
    }
    $all_ap = Authoritative_Plant::getAllFromDb(['flag_delete' => false], $DB);
    echo '<ul id="list-of-authoritative-plants" class="all-authoritative-plants">' . "\n";
    foreach ($all_ap as $ap) {
        if ($USER->canActOnTarget($ACTIONS['view'], $ap)) {
            echo $ap->renderAsListItem();
        }
    }
    echo '</ul>' . "\n";
    //        echo 'TODO: implement list action';
}
if ($action == 'view') {
    if ($USER->canActOnTarget($ACTIONS['edit'], $ap)) {
        echo '<div id="actions">' . $ap->renderAsButtonEdit() . '</div>' . "\n";
    }
    echo $ap->renderAsView();
    echo '<script src="' . APP_ROOT_PATH . '/js/plant_image_viewer.js"></script>' . "\n";
 public function getTargets()
 {
     switch ($this->target_type) {
         case 'global_notebook':
             return Notebook::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_metadata':
             return Metadata_Structure::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_plant':
             return Authoritative_Plant::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_specimen':
             return Specimen::getAllFromDb([], $this->dbConnection);
             break;
         case 'notebook':
             return array(Notebook::getOneFromDb(['notebook_id' => $this->target_id], $this->dbConnection));
             break;
         case 'metadata_structure':
             return array(Metadata_Structure::getOneFromDb(['metadata_structure_id' => $this->target_id], $this->dbConnection));
             break;
         case 'plant':
             return array(Authoritative_Plant::getOneFromDb(['authoritative_id' => $this->target_id], $this->dbConnection));
             break;
         case 'specimen':
             return array(Specimen::getOneFromDb(['specimen_id' => $this->target_id], $this->dbConnection));
             break;
         default:
             return array();
     }
 }