protected function updateTextblockDescriptions()
 {
     global $sugar_version;
     $sequence = $_POST['textblockSequence'];
     $textblockIds = explode(' ', trim($sequence));
     foreach ($textblockIds as $textblockId) {
         $key = "description_{$textblockId}";
         $userEditedDescription = $_POST[$key];
         if ($userEditedDescription == '') {
             //$GLOBALS['log']->error('skipping texblock save- empty description');
             $sequence = trim(str_replace($textblockId, '', $sequence));
             //do not save if it is empty
             continue;
         }
         if ($originalTextblock = oqc_TextBlock::getFromId($textblockId)) {
             // it is a TextBlock instance
             // if the user changed the description copy the information from the TextBlock instance into a new instance of EditedTextBlock
             if ($originalTextblock->description != $userEditedDescription) {
                 $changes = array('field_name' => $originalTextblock->name, 'data_type' => 'text', 'before' => $originalTextblock->description, 'after' => $userEditedDescription);
                 if (floatval(substr($sugar_version, 0, 3)) > 6.3) {
                     $this->bean->db->save_audit_records($this->bean, $changes);
                 } else {
                     $this->bean->dbManager->helper->save_audit_records($this->bean, $changes);
                 }
                 $editedTextblock = new oqc_EditedTextBlock();
                 $editedTextblock->name = $originalTextblock->name;
                 $editedTextblock->textblock_id = $originalTextblock->id;
                 $editedTextblock->description = $userEditedDescription;
                 $editedTextblock->save();
                 //$GLOBALS['log']->error('saved as edited original template texblock');
                 if (!empty($textblockId) && !empty($editedTextblock->id)) {
                     $sequence = str_replace($textblockId, $editedTextblock->id, $sequence);
                 } else {
                     $GLOBALS['log']->fatal('textblockId or editedTextblock->id is empty');
                 }
             }
             // check if textBlock is newly added
             if (strpos($this->bean->textblocksequence, $textblockId) === false) {
                 $changes = array('field_name' => $originalTextblock->name, 'data_type' => 'text', 'before' => '<n/a>', 'after' => $userEditedDescription);
                 if (floatval(substr($sugar_version, 0, 3)) > 6.3) {
                     $this->bean->db->save_audit_records($this->bean, $changes);
                 } else {
                     $this->bean->dbManager->helper->save_audit_records($this->bean, $changes);
                 }
             }
         } else {
             if ($editedTextblock = oqc_EditedTextBlock::getFromId($textblockId)) {
                 // it has to be an EditedTextBlock instance
                 // update the description and save it
                 if ($editedTextblock->description != $userEditedDescription) {
                     //$GLOBALS['log']->error('saved as edited template texblock that was saved before');
                     $changes = array('field_name' => $editedTextblock->name, 'data_type' => 'text', 'before' => $editedTextblock->description, 'after' => $userEditedDescription);
                     if (floatval(substr($sugar_version, 0, 3)) > 6.3) {
                         $this->bean->db->save_audit_records($this->bean, $changes);
                     } else {
                         $this->bean->dbManager->helper->save_audit_records($this->bean, $changes);
                     }
                     $editedTextblock->id = '';
                     //1.7.6 avoid Quotes inheriting textblock from linked Contract and vice versa
                     $editedTextblock->description = $userEditedDescription;
                     $editedTextblock->save();
                     //1.7.6 getting new id
                     if (!empty($textblockId) && !empty($editedTextblock->id)) {
                         $sequence = str_replace($textblockId, $editedTextblock->id, $sequence);
                     }
                 }
             } else {
                 //2.0 this is former free text saving part
                 global $app_list_strings;
                 //$GLOBALS['log']->error('saving as free text edited texblock');
                 $changes = array('field_name' => $app_list_strings["oqc"]["Textblocks"]["freeText"], 'data_type' => 'text', 'before' => '<n/a>', 'after' => $userEditedDescription);
                 if (floatval(substr($sugar_version, 0, 3)) > 6.3) {
                     $this->bean->db->save_audit_records($this->bean, $changes);
                 } else {
                     $this->bean->dbManager->helper->save_audit_records($this->bean, $changes);
                 }
                 $newTextblock = new oqc_EditedTextBlock();
                 $newTextblock->name = $app_list_strings["oqc"]["Textblocks"]["freeText"];
                 $newTextblock->id = '';
                 //$newTextblock->id = $textblockId;
                 $newTextblock->textblock_id = '';
                 $newTextblock->description = $userEditedDescription;
                 $newTextblock->save();
                 if (!empty($textblockId) && !empty($newTextblock->id)) {
                     $sequence = str_replace($textblockId, $newTextblock->id, $sequence);
                 } else {
                     $GLOBALS['log']->fatal('textblockId or editedTextblock->id is empty');
                 }
             }
         }
     }
     return $sequence;
 }
<?php

session_start();
header("Content-type: application/json");
if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
chdir('..');
require_once 'include/entryPoint.php';
require_once 'modules/oqc_TextBlock/oqc_TextBlock.php';
if (array_key_exists('id', $_REQUEST)) {
    $textblock = new oqc_TextBlock();
    if ($textblock->retrieve($_REQUEST['id'])) {
        require_once 'include/utils.php';
        $json = getJSONobj();
        $jsonArray = array(0 => array("id" => $textblock->id, "title" => $textblock->name, "description" => html_entity_decode($textblock->description, ENT_COMPAT, 'UTF-8')));
        $encoded = $json->encode($jsonArray);
        echo $encoded;
    }
}
session_write_close();
function getDefaultTextblocks()
{
    $textblock = new oqc_TextBlock();
    return $textblock->get_list('', 'is_default=1');
}
<?php

if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
chdir('..');
require_once 'include/entryPoint.php';
require_once 'modules/oqc_TextBlock/oqc_TextBlock.php';
$textblock = new oqc_TextBlock();
$a = $textblock->get_list('', 'is_default=1');
$a = $a['list'];
$json = getJSONobj();
$b = array();
foreach ($a as $textblock) {
    $b[] = array("id" => $textblock->id, "title" => $textblock->name, "description" => $textblock->description);
}
$encoded = $json->encode($b);
echo $encoded;
 public static function getFromId($id)
 {
     $textblock = new oqc_TextBlock();
     return $textblock->retrieve($id);
 }