tripal_cv_admin.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. /**
  3. * Purpose: Provide Guidance to new Tripal Admin
  4. *
  5. * @return HTML Formatted text
  6. *
  7. * @ingroup tripal_cv
  8. */
  9. function tripal_cv_module_description_page() {
  10. $text = '';
  11. $text = '<br><h3>Tripal Controlled Vocabulary Administrative Tools Quick Links</h3>';
  12. $text .= '<ul>';
  13. $text .= '<li>' . l('Add a Vocabulary', 'admin/tripal/tripal_cv/cv/add') . '</li>';
  14. $text .= '<li>' . l('Edit a Vocabulary', 'admin/tripal/tripal_cv/cv/edit') . '</li>';
  15. $text .= '<li>' . l('Load ontology with OBO file', 'admin/tripal/tripal_cv/obo_loader') . '</li>';
  16. $text .= '<li>' . l('Add a Term', 'admin/tripal/tripal_cv/cvterm/add') . '</li>';
  17. $text .= '<li>' . l('Edit a Term', 'admin/tripal/tripal_cv/cvterm/edit') . '</li>';
  18. $text .= '<li>' . l('Update cvtermpath', 'admin/tripal/tripal_cv/cvtermpath') . '</li>';
  19. $text .= '</ul>';
  20. $text .= '<h3>Module Description:</h3>';
  21. $text .= '<p>The Tripal CV (Controlled Vocabularies) Module provides
  22. functionality for managing controlled vocabularies and the terms they are
  23. comprised of. The flexibility and extendibility of the chado schema depends
  24. on controlled vocabularies. For example, by using a controlled vocabulary for
  25. feature types the chado schema can describe features of any type, even those
  26. we have not concieved of yet.</p>';
  27. $text .= '<h3>Setup Instructions:</h3>';
  28. $text .= '<p>After installation of the controlled vocabulary module, the following tasks should be performed:</p>';
  29. $text .= '<ol>';
  30. $text .= '<li><p><b>Set Permissions</b>: The cv module supports the Drupal user permissions interface for
  31. controlling access to cv content and functions. These permissions include viewing,
  32. creating, editing or administering of
  33. cv content. The default is that only the original site administrator has these
  34. permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
  35. <a href="' . url('admin/user/user') . '">assign users to roles</a> and
  36. <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the cv content to
  37. those roles. For a simple setup, allow anonymous users access to view organism content and
  38. allow the site administrator all other permissions.</p></li>';
  39. $text .= '<li><b>Loading of Ontologies/Controlled Vocabularies</b>: You can access this loader at '.
  40. l('Admin->Tripal Management->Tripal CV->Load Ontology With OBO File', 'admin/tripal/tripal_cv/obo_loader')
  41. .'. This loader allows you to choose from a list of common ontologies or
  42. enter the URL or location to an OBO file. Even the list of common
  43. ontologies is using a URL ensuring you get the most up to date ontology.</p>';
  44. $text .= '<p>This loader adds a Tripal Job which then waits in a queue to
  45. be launched. To launch Tripal Jobs either navidate to the root of your
  46. drupal installation and execute "php sites/all/modules/tripal/tripal_core/
  47. tripal_launch_jobs.php <drupal user>" or set up a cron job (See user manual
  48. for more details).</p>';
  49. $text .= '<p>NOTE: in some cases, community developed ontologies for your
  50. data may not yet be developed. In this case, it is suggested that you begin
  51. developement of an ontology using one of the online tools. You might find
  52. that many researchers are trying to deal with the same data and are willing
  53. to help you in this endevor. You can ' . l('create a controlled vocabulary', 'admin/tripal/tripal_cv/add_cv') . ' and '
  54. . l('add terms to it', 'admin/tripal/tripal_cv/add_cvterm') . ' to provide functionality to your site while you are waiting
  55. for the ontology to be developed.</p></li>';
  56. $text .= '</ol>';
  57. $text .= '<h3>Features of this Module:</h3>';
  58. $text .= '<p>Aside from the data loading described above, the Tripal Controlled Vocabulary (CV) module also provides the following functionality:</p>';
  59. $text .= '<ul>';
  60. $text .= '<li><b>Create/Update/Delete A Controlled Vocaulbulary</b>: to create your own controlled vocabulary go to '.
  61. l('Admin->Tripal Management->Tripal CV->Add a Controlled Vocabulary', 'admin/tripal/tripal_cv/add_cv')
  62. .' and fill out the form provided.To Update/Delete a controlled vocabulary
  63. go to ' . l('Admin->Tripal Management->Tripal CV->Update/Delete Controlled Vocabulary', 'admin/tripal/tripal_cv/edit_cv')
  64. .', select the existing controlled vocabulary you want to modify and then
  65. edit it as desired. This only modifies the name, description of a
  66. controlled vocabulary. See the next section for adding, removing, editing
  67. the term a controlled vocabulary contains.</li>';
  68. $text .= '<li><b>Create a Controlled Vocaulbulary Term</b>: To Add a term to an already existing controlled vocabulary
  69. go to ' . l('Admin->Tripal Management->Tripal CV->Add a Controlled Vocabulary Term', 'admin/tripal/tripal_cv/add_cvterm')
  70. .', select the controlled vocabulary you want to add terms to and then fill
  71. out the form.</li>';
  72. $text .= '<li><b>Controlled Vocabulary Term Browser</b>: This module provides a ' . l('basic listing', 'admin/tripal/tripal_cv/list_cvterms') . ' of controlled vocabulry terms for
  73. for all vocabularies currently in chado. It does not require indexing for Drupal searching but relies on Drupal Views.
  74. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed.</li>';
  75. $text .= '<li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
  76. a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
  77. It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
  78. and create custom lists without PHP programming or customization of Tripal source code. Views can also
  79. be created to filter content that has not yet been synced with Druapl in order to protect access to non
  80. published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
  81. Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>';
  82. $text .= '</ul>';
  83. return $text;
  84. }
  85. /**
  86. * Purpose: Provides the form for Updating and Deleteing existing
  87. * chado controlled vocabularies (See chado cv table)
  88. *
  89. * @ingroup tripal_cv
  90. */
  91. function tripal_cv_edit_page() {
  92. $output .= drupal_get_form('tripal_cv_select_form');
  93. $output .= '<div id="db-edit-div">Please select a vocabulary above to view or edit</div>';
  94. return $output;
  95. }
  96. /**
  97. * Purpose: Provides the actual "Select CV" form on the Update/Delete Controlled
  98. * Vocabulary page. This form also triggers the edit javascript
  99. * @todo Modify this form to use Drupal AJAX
  100. *
  101. * @ingroup tripal_cv
  102. */
  103. function tripal_cv_select_form() {
  104. // get a list of db from chado for user to choose
  105. $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
  106. $results = chado_query($sql);
  107. $cvs = array();
  108. $cvs[] = '';
  109. while ($cv = db_fetch_object($results)) {
  110. $cvs[$cv->cv_id] = $cv->name;
  111. }
  112. $form['cvid'] = array(
  113. '#title' => t('Controlled Vocabulary/Ontology Name'),
  114. '#type' => 'select',
  115. '#options' => $cvs,
  116. '#ahah' => array(
  117. 'path' => 'admin/tripal/tripal_cv/cv/edit/js',
  118. 'wrapper' => 'db-edit-div',
  119. 'effect' => 'fade',
  120. 'event' => 'change',
  121. 'method' => 'replace',
  122. ),
  123. );
  124. return $form;
  125. }
  126. /**
  127. * Purpose: The edit controlled vocabulary javascript
  128. *
  129. * @ingroup tripal_cv
  130. */
  131. function tripal_ajax_cv_edit() {
  132. // get the database id, build the form and then return the JSON object
  133. $cvid = filter_xss($_POST['cvid']);
  134. $form = drupal_get_form('tripal_cv_edit_form', $cvid);
  135. drupal_json(array('status' => TRUE, 'data' => $form));
  136. }
  137. /**
  138. * Purpose: Provides a form to allow updating/deleteing of controlled vocabularies
  139. *
  140. * @ingroup tripal_cv
  141. */
  142. function tripal_cv_edit_form(&$form_state = NULL, $cvid = NULL) {
  143. $sql = "SELECT * FROM {cv} WHERE cv_id = %d ";
  144. $cv = db_fetch_object(chado_query($sql, $cvid));
  145. // set the default values. If there is a value set in the
  146. // form_state then let's use that, otherwise, we'll pull
  147. // the values from the database
  148. $default_db = $form_state['values']['name'];
  149. $default_desc = $form_state['values']['description'];
  150. $default_url = $form_state['values']['url'];
  151. $default_urlprefix = $form_state['values']['urlprefix'];
  152. if (!$default_db) {
  153. $default_cv = $cv->name;
  154. }
  155. if (!$default_desc) {
  156. $default_desc = $cv->definition;
  157. }
  158. $form['cvid'] = array(
  159. '#type' => 'hidden',
  160. '#value' => $cvid
  161. );
  162. $form['name']= array(
  163. '#type' => 'textfield',
  164. '#title' => t("Controlled Vocabulary name"),
  165. '#description' => t('Please enter the name for this vocabulary.'),
  166. '#required' => FALSE,
  167. '#default_value' => $default_cv,
  168. '#weight' => 1
  169. );
  170. $form['definition']= array(
  171. '#type' => 'textarea',
  172. '#title' => t('Description'),
  173. '#description' => t('Please enter a description for this vocabulary'),
  174. '#default_value' => $default_desc,
  175. '#weight' => 2
  176. );
  177. $form['update'] = array(
  178. '#type' => 'submit',
  179. '#value' => t('Update'),
  180. '#weight' => 5,
  181. '#executes_submit_callback' => TRUE,
  182. );
  183. $form['delete'] = array(
  184. '#type' => 'submit',
  185. '#value' => t('Delete'),
  186. '#weight' => 6,
  187. '#executes_submit_callback' => TRUE,
  188. );
  189. $form['#redirect'] = 'admin/tripal/tripal_cv';
  190. return $form;
  191. }
  192. /**
  193. * Purpose: The submit function of the update/delete controlled vocabulary form
  194. *
  195. * @ingroup tripal_cv
  196. */
  197. function tripal_cv_edit_form_submit($form, &$form_state) {
  198. $name = $form_state['values']['name'];
  199. $desc = $form_state['values']['definition'];
  200. $cvid = $form_state['values']['cvid'];
  201. $op = $form_state['values']['op'];
  202. if (strcmp($op, 'Update') == 0) {
  203. $sql = "
  204. UPDATE {cv} SET
  205. name = '%s',
  206. definition = '%s'
  207. WHERE cv_id = %d
  208. ";
  209. $db = chado_query($sql, $name, $desc, $cvid);
  210. if ($db) {
  211. drupal_set_message(t("Controlled vocabulary updated"));
  212. }
  213. else {
  214. drupal_set_message(t("Failed to update controlled vocabulary."), 'error');
  215. }
  216. }
  217. if (strcmp($op, 'Delete')==0) {
  218. $sql = "
  219. DELETE FROM {cv}
  220. WHERE cv_id = %d
  221. ";
  222. $db = chado_query($sql, $cvid);
  223. if ($db) {
  224. drupal_set_message(t("Controlled vocabulary deleted"));
  225. }
  226. else {
  227. drupal_set_message(t("Failed to delete controlled vocabulary."), 'error');
  228. }
  229. }
  230. }
  231. /**
  232. * Purpose: Provides the Add controlled vocabulary form
  233. *
  234. * @ingroup tripal_cv
  235. */
  236. function tripal_cv_add_form(&$form_state = NULL) {
  237. $form['cvid'] = array(
  238. '#type' => 'hidden',
  239. '#value' => $cvid
  240. );
  241. $form['name']= array(
  242. '#type' => 'textfield',
  243. '#title' => t("Controlled Vocabulary name"),
  244. '#description' => t('Please enter the name for this vocabulary. This field will be ignored if an OBO file or URL is provided above'),
  245. '#required' => FALSE,
  246. '#default_value' => $default_cv,
  247. '#weight' => 1
  248. );
  249. $form['definition']= array(
  250. '#type' => 'textarea',
  251. '#title' => t('Description'),
  252. '#description' => t('Please enter a description for this vocabulary'),
  253. '#default_value' => $default_desc,
  254. '#weight' => 2
  255. );
  256. $form['add'] = array(
  257. '#type' => 'submit',
  258. '#value' => t('Add'),
  259. '#weight' => 5,
  260. '#executes_submit_callback' => TRUE,
  261. );
  262. $form['#redirect'] = 'admin/tripal/tripal_cv';
  263. return $form;
  264. }
  265. /**
  266. * Purpose: The submit function for the add controlled vocabulary form
  267. *
  268. * @ingroup tripal_cv
  269. */
  270. function tripal_cv_add_form_submit($form, &$form_state) {
  271. $name = $form_state['values']['name'];
  272. $desc = $form_state['values']['definition'];
  273. $sql = "
  274. INSERT INTO {cv}
  275. (name,definition)
  276. VALUES
  277. ('%s','%s')
  278. ";
  279. $db = chado_query($sql, $name, $desc);
  280. if ($db) {
  281. drupal_set_message(t("Controlled vocabulary added"));
  282. }
  283. else {
  284. drupal_set_message(t("Failed to add controlled vocabulary."), 'error');
  285. }
  286. }
  287. /**
  288. * Purpose: Provides the form that allows adding of terms to an existing
  289. * controlled vocabulary
  290. *
  291. * @ingroup tripal_cv
  292. */
  293. function tripal_cv_cvterm_form(&$form_state, $action = 'add') {
  294. tripal_core_ahah_init_form();
  295. $form = array();
  296. // get defaults
  297. $cv_id = $form_state['values']['cv_id'] ? $form_state['values']['cv_id'] : FALSE;
  298. $name = $form_state['values']['name'] ? $form_state['values']['name'] : '';
  299. // if we have a cv_id and a term name then get the rest of the term details
  300. if ($cv_id and $name) {
  301. $values = array(
  302. 'cv_id' => $cv_id,
  303. 'name' => $name,
  304. );
  305. $results = tripal_core_chado_select('cvterm', array('*'), $values);
  306. if (!$results or count($results) == 0) {
  307. // we can't find the cvterm so reset the name to blank
  308. $name = '';
  309. }
  310. else {
  311. $cvterm = $results[0];
  312. $definition = $cvterm->definition;
  313. $is_relationshiptype = $cvterm->is_relationshiptype;
  314. $is_obsolete = $cvterm->is_obsolete;
  315. // now get the database
  316. $values = array('dbxref_id' => $cvterm->dbxref_id);
  317. $results = tripal_core_chado_select('dbxref', array('*'), $values);
  318. $dbxref = $results[0];
  319. $accession = $dbxref->accession;
  320. $db_id = $dbxref->db_id;
  321. }
  322. }
  323. $values = array();
  324. $columns = array('cv_id', 'name');
  325. $options = array('order_by' => array('name' => 'ASC'));
  326. $results = tripal_core_chado_select('cv', $columns, $values, $options);
  327. $cvs = array();
  328. $cvs[] = '';
  329. foreach ($results as $cv) {
  330. $cvs[$cv->cv_id] = $cv->name;
  331. }
  332. $form['wrapper-top'] = array(
  333. '#type' => 'markup',
  334. '#value' => '<div id="cvterm-form">',
  335. );
  336. $form['form_action'] = array(
  337. '#type' => 'hidden',
  338. '#value' => $action,
  339. );
  340. $form['cv_id'] = array(
  341. '#title' => t('Controlled Vocabulary (Ontology) Name'),
  342. '#type' => 'select',
  343. '#options' => $cvs,
  344. '#required' => TRUE,
  345. '#default_value' => $cv_id,
  346. '#ahah' => array(
  347. 'path' => 'admin/tripal/tripal_cv/cvterm/ahah',
  348. 'wrapper' => 'cvterm-form',
  349. 'event' => 'change',
  350. 'method' => 'replace',
  351. ),
  352. );
  353. if ($cv_id) {
  354. $form['add_cvterm'] = array(
  355. '#type' => 'fieldset',
  356. '#title' => t('Term Details'),
  357. '#prefix' => '<div id="cvterm-add-div">',
  358. '#suffix' => '</div>'
  359. );
  360. $description = t('Please enter the name for this vocabulary term.');
  361. if ($action == 'edit') {
  362. $description = t('Enter the name of the term to edit. This field will update automatically as you type. Click outside of the box after entering the term.');
  363. }
  364. $form['add_cvterm']['name']= array(
  365. '#type' => 'textfield',
  366. '#title' => t("Term Name"),
  367. '#description' => $description,
  368. '#default_value' => $name,
  369. '#required' => TRUE,
  370. );
  371. if ($action == 'edit') {
  372. if ($name) {
  373. $form['add_cvterm']['name']['#attributes'] = array('readonly' => 'readonly');
  374. $form['add_cvterm']['name']['#description'] = 'The term name cannot be changed. If the name is incorrect, please create a new term and make this one as obsolete.';
  375. } else {
  376. $form['add_cvterm']['name']['#autocomplete_path'] = "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id";
  377. $form['add_cvterm']['name']['#ahah'] = array(
  378. 'path' => 'admin/tripal/tripal_cv/cvterm/ahah',
  379. 'wrapper' => 'cvterm-form',
  380. 'method' => 'replace',
  381. );
  382. }
  383. }
  384. if ($action == 'add' or $name) {
  385. $form['add_cvterm']['definition']= array(
  386. '#type' => 'textarea',
  387. '#title' => t('Description'),
  388. '#description' => t('Please enter a description for this term'),
  389. '#default_value' => $definition,
  390. );
  391. $form['add_cvterm']['is_relationshiptype'] = array(
  392. '#type' => 'checkbox',
  393. '#title' => t('This term describes a relationship?'),
  394. '#default_value' => $is_relationshiptype,
  395. );
  396. $form['add_cvterm']['is_obsolete'] = array(
  397. '#type' => 'checkbox',
  398. '#title' => t('This term is obsolete?'),
  399. '#default_value' => $is_obsolete,
  400. );
  401. $values = array();
  402. $columns = array('db_id', 'name');
  403. $options = array('order_by' => array('name' => 'ASC'));
  404. $results = tripal_core_chado_select('db', $columns, $values, $options);
  405. $dbs = array();
  406. $dbs[] = '';
  407. foreach ($results as $db) {
  408. $dbs[$db->db_id] = $db->name;
  409. }
  410. $form['add_cvterm']['db_id'] = array(
  411. '#type' => 'select',
  412. '#title' => t('Database'),
  413. '#description' => t('All terms must be assocated with an external database.
  414. Please select the external database to associate with
  415. this term'),
  416. '#options' => $dbs,
  417. '#default_value' => $db_id,
  418. '#required' => TRUE,
  419. );
  420. if ($action == 'edit') {
  421. // we don't want to allow the user to change the database on an edit.
  422. $form['add_cvterm']['db_id']['#disabled'] = TRUE;
  423. $form['add_cvterm']['db_id']['#description'] = 'The database to which this term belongs cannot be changed.';
  424. }
  425. $form['add_cvterm']['accession']= array(
  426. '#type' => 'textfield',
  427. '#title' => t("Accession"),
  428. '#description' => t('If this term has an existing accession (unique identifier) in the database
  429. please enter that here. If the accession is numeric with a database prefix (e.g. GO:003023), please
  430. enter just the numeric value. The database prefix will be appended whenever the term is displayed.
  431. If the accession is not numeric then enter it as is. If no value is provied, the term name
  432. provided above will be used as the accession.'),
  433. '#required' => FALSE,
  434. '#default_value' => $accession,
  435. );
  436. if ($action == 'edit') {
  437. $form['add_cvterm']['accession']['#attributes'] = array('readonly' => 'readonly');
  438. $form['add_cvterm']['accession']['#description'] = 'Cannot change the term accession.';
  439. }
  440. $button_text = 'Add Term';
  441. if ($action == 'edit') {
  442. $button_text = 'Update Term';
  443. }
  444. $form['add_cvterm']['submit'] = array(
  445. '#type' => 'submit',
  446. '#value' => $button_text,
  447. );
  448. } // end if name selected (or action == 'add')
  449. } //end of if cv selected
  450. $form['wrapper-bottom'] = array(
  451. '#type' => 'markup',
  452. '#value' => '</div>',
  453. );
  454. return $form;
  455. }
  456. /*
  457. * @ingroup tripal_cv
  458. */
  459. function tripal_cv_cvterm_name_autocomplete($cv_id, $string = '') {
  460. $sql = "SELECT cvterm_id, name FROM cvterm WHERE cv_id = %d and name like '%s%%' ORDER by name";
  461. $results = chado_query($sql, $cv_id, $string);
  462. $items = array();
  463. while($term = db_fetch_object($results)) {
  464. $items[$term->name] = $term->name;
  465. }
  466. drupal_json($items);
  467. }
  468. /**
  469. * Purpose: Validates the input for adding a cvterm
  470. *
  471. * @ingroup tripal_cv
  472. */
  473. function tripal_cv_cvterm_form_validate($form, &$form_state) {
  474. // Ensure that submit does not get called unless the AHAH in the form was called
  475. if (!empty($form_state['ahah_submission'])) {
  476. return;
  477. }
  478. }
  479. /**
  480. * Purpose: Adds terms to an existing controlled vocabulary
  481. *
  482. * @ingroup tripal_cv
  483. */
  484. function tripal_cv_cvterm_form_submit($form, &$form_state) {
  485. // Ensure the AHAH in the form was called
  486. if (!empty($form_state['ahah_submission'])) {
  487. return;
  488. }
  489. // get the database
  490. $values = array('db_id' => $form_state['values']['db_id']);
  491. $results = tripal_core_chado_select('db', array('name'), $values);
  492. if (!$results or count($results) == 0){
  493. drupal_set_message(t('Unable to add term. Cannot find the database.'), 'error');
  494. return;
  495. }
  496. $db = $results[0];
  497. // get the cv
  498. $values = array('cv_id' => $form_state['values']['cv_id']);
  499. $results = tripal_core_chado_select('cv', array('name'), $values);
  500. if (!$results or count($results) == 0){
  501. drupal_set_message(t('Unable to add term. Cannot find the vocabulary.'), 'error');
  502. return;
  503. }
  504. $cv = $results[0];
  505. // get the accession for this term
  506. $accession = $form_state['values']['accession'];
  507. if (!$accession) {
  508. $accession = $form_state['values']['name'];
  509. }
  510. if (is_numeric($accession)) {
  511. $accession = $db->name . ":" . $accession;
  512. }
  513. $update = 0;
  514. if ($form_state['values']['form_action'] == 'edit') {
  515. $update = 1;
  516. }
  517. // now add the term
  518. $term = array(
  519. 'name' => $form_state['values']['name'],
  520. 'namespace' => $cv->name,
  521. 'id' => $accession,
  522. 'def' => $form_state['values']['definition'],
  523. 'is_obsolete' => $form_state['values']['is_obsolete'],
  524. );
  525. $is_relationship = $form_state['values']['is_relationshiptype'];
  526. $cvterm = tripal_cv_add_cvterm($term, $cv->name, $is_relationship, $update, $db->name);
  527. if ($cvterm) {
  528. if (!$update) {
  529. drupal_set_message('Term added successfully.');
  530. }
  531. else {
  532. drupal_set_message('Term updated successfully.');
  533. }
  534. }
  535. else {
  536. drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
  537. }
  538. }
  539. /**
  540. * Purpose: This function gets called when the selecting of a cv from
  541. * the select list triggers it. This function simply rebuilds the form
  542. * with new information. No elements are created here
  543. *
  544. * @ingroup tripal_cv
  545. */
  546. function tripal_cv_cvterm_callback() {
  547. $status = TRUE;
  548. // prepare and render the form
  549. $form = tripal_core_ahah_prepare_form();
  550. $data = drupal_render($form);
  551. // bind javascript events to the new objects that will be returned
  552. // so that AHAH enabled elements will work.
  553. $settings = tripal_core_ahah_bind_events();
  554. // return the updated JSON
  555. drupal_json(
  556. array(
  557. 'status' => $status,
  558. 'data' => $data,
  559. 'settings' => $settings,
  560. )
  561. );
  562. }
  563. /**
  564. * Cvterm path form submit
  565. *
  566. * @ingroup tripal_cv
  567. */
  568. function tripal_cv_cvtermpath_form_submit($form, &$form_state) {
  569. global $user;
  570. $cvid = $form_state['values']['cvid'];
  571. // first get the controlled vocabulary name:
  572. $cv = db_fetch_object(chado_query("SELECT * FROM {cv} WHERE cv_id = %d", $cvid));
  573. // Submit a job to update cvtermpath
  574. $job_args = array($cvid);
  575. if ($form_state['values']['op'] == t('Update cvtermpath')) {
  576. tripal_add_job("Update cvtermpath: $cv->name", 'tripal_cv',
  577. 'tripal_cv_update_cvtermpath', $job_args, $user->uid);
  578. }
  579. }