How the Guides Work (Under the Hood)

The guide functions are spectacularly complicated, unfortunately.  These are some notes to try to help you figure it out.

BUT this doc is sorta old.  So maybe not everything is true!

// how Find Box clone works

* User clicks on "Find Box" (loads helpers/disover.php)
* User selects guide they want to use from (loads helpers/find_results.php)
* User clicks on + symbol (js variables (in parent scope) populated with id and item_type)
* Modal closes
* plantClone function (guide.js) is called
* helpers/guide_data.php is called with flag of drop, from like "pluslet-cloneid-" + clone_id,
and the type (i.e., Basic, Heading, etc.)
* New sp_Pluslet object (actually, a specific object that inherits from sp_Pluslet)
is created, populated with appropriate data from original, and then $this->_pluslet_id
is emptied, so it's treated as a new pluslet to be inserted into database

// How Save Guide works

* When a change to the guide is seen in guide.js, the save button appears
* Upon click:
** We check if all required fields are filled out (this should be moved outside
this function)
** We loop through each div with a name*=modified-pluslet
*** Determine update_id, our_instance, new_title, item_type
*** If item_type == Basic, thebody variable is populated by data from FCKeditor;
otherwise, thebody comes from '#pluslet-update-body-'+update_id
*** We reset the item_type to be only the item type, i.e., Basic (maybe this should
be fixed)
*** Check for clones (check "#pluslet-" + update_id for a "clone" class). Make
ourflag update or insert (for clone)
*** Load helpers/guide_data.php, pass in values + flag (insert or update).  This
then:
**** Modifies database -- modifyDB("", "insert") or modifyDB($_POST["update_id"], "update");
**** Creates an object with the new or updated content, returns
*** guide.js replaces the old pluslet div with the new content [should that old
object be destroyed?]
** We repeat for new pluslets:  'div[name*=new-pluslet]'
** We repeat for cloned (but unchanged) pluslet:  'div[name*=cloned-pluslet]' [is this still
necessary?]
** We hide our save button
** After a pause (to give time for the dom to reassemble completely), we call SaveGuide()
* SaveGuide() notes the ids and locations of every pluslet on the page
* Calls helpers/save_guide.php which updates the pluslet_sections table, and
updates chchchanges table
