public function startForm($p_blockId, $p_isValid = false)
 {
     // load type
     $out = CcBlockQuery::create()->findPk($p_blockId);
     if ($out->getDbType() == "static") {
         $blockType = 0;
     } else {
         $blockType = 1;
     }
     $spType = new Zend_Form_Element_Radio('sp_type');
     $spType->setLabel(_('Set smart block type:'))->setDecorators(array('viewHelper'))->setMultiOptions(array('static' => _('Static'), 'dynamic' => _('Dynamic')))->setValue($blockType);
     $this->addElement($spType);
     $bl = new Application_Model_Block($p_blockId);
     $storedCrit = $bl->getCriteria();
     //need to convert criteria to be displayed in the user's timezone if there's some timestamp type.
     self::convertTimestamps($storedCrit["crit"]);
     /* $modRoadMap stores the number of same criteria
      * Ex: 3 Album titles, and 2 Track titles
      * We need to know this so we display the form elements properly
      */
     $modRowMap = array();
     $openSmartBlockOption = false;
     if (!empty($storedCrit)) {
         $openSmartBlockOption = true;
     }
     $criteriaKeys = array();
     if (isset($storedCrit["crit"])) {
         $criteriaKeys = array_keys($storedCrit["crit"]);
     }
     $numElements = count($this->getCriteriaOptions());
     for ($i = 0; $i < $numElements; $i++) {
         $criteriaType = "";
         if (isset($criteriaKeys[$i])) {
             $critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
         } else {
             $critCount = 1;
         }
         $modRowMap[$i] = $critCount;
         /* Loop through all criteria with the same field
          * Ex: all criteria for 'Album'
          */
         for ($j = 0; $j < $critCount; $j++) {
             /****************** CRITERIA ***********/
             if ($j > 0) {
                 $invisible = ' sp-invisible';
             } else {
                 $invisible = '';
             }
             $criteria = new Zend_Form_Element_Select("sp_criteria_field_" . $i . "_" . $j);
             $criteria->setAttrib('class', 'input_select sp_input_select' . $invisible)->setValue('Select criteria')->setDecorators(array('viewHelper'))->setMultiOptions($this->getCriteriaOptions());
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteria->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
                 $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
             }
             $this->addElement($criteria);
             /****************** MODIFIER ***********/
             $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_" . $i . "_" . $j);
             $criteriaModifers->setValue('Select modifier')->setAttrib('class', 'input_select sp_input_select')->setDecorators(array('viewHelper'));
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteriaModifers->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 if ($criteriaType == "s") {
                     $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
                 } else {
                     $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
                 }
                 $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
             } else {
                 $criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
             }
             $this->addElement($criteriaModifers);
             /****************** VALUE ***********/
             $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
             $criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
             if ($i != 0 && !isset($criteriaKeys[$i])) {
                 $criteriaValue->setAttrib('disabled', 'disabled');
             }
             if (isset($criteriaKeys[$i])) {
                 $criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
             }
             $this->addElement($criteriaValue);
             /****************** EXTRA ***********/
             $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_" . $i . "_" . $j);
             $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')->setDecorators(array('viewHelper'));
             if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) {
                 $criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
                 $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
             } else {
                 $criteriaExtra->setAttrib('disabled', 'disabled');
             }
             $this->addElement($criteriaExtra);
         }
         //for
     }
     //for
     $repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks');
     $repeatTracks->setDecorators(array('viewHelper'))->setLabel(_('Allow Repeat Tracks:'));
     if (isset($storedCrit["repeat_tracks"])) {
         $repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1 ? true : false);
     }
     $this->addElement($repeatTracks);
     $limit = new Zend_Form_Element_Select('sp_limit_options');
     $limit->setAttrib('class', 'sp_input_select')->setDecorators(array('viewHelper'))->setMultiOptions($this->getLimitOptions());
     if (isset($storedCrit["limit"])) {
         $limit->setValue($storedCrit["limit"]["modifier"]);
     }
     $this->addElement($limit);
     $limitValue = new Zend_Form_Element_Text('sp_limit_value');
     $limitValue->setAttrib('class', 'sp_input_text_limit')->setLabel(_('Limit to'))->setDecorators(array('viewHelper'));
     $this->addElement($limitValue);
     if (isset($storedCrit["limit"])) {
         $limitValue->setValue($storedCrit["limit"]["value"]);
     } else {
         // setting default to 1 hour
         $limitValue->setValue(1);
     }
     //getting block content candidate count that meets criteria
     $bl = new Application_Model_Block($p_blockId);
     if ($p_isValid) {
         $files = $bl->getListofFilesMeetCriteria();
         $showPoolCount = true;
     } else {
         $files = null;
         $showPoolCount = false;
     }
     $generate = new Zend_Form_Element_Button('generate_button');
     $generate->setAttrib('class', 'btn btn-small');
     $generate->setAttrib('title', _('Generate playlist content and save criteria'));
     $generate->setIgnore(true);
     $generate->setLabel(_('Generate'));
     $generate->setDecorators(array('viewHelper'));
     $this->addElement($generate);
     $shuffle = new Zend_Form_Element_Button('shuffle_button');
     $shuffle->setAttrib('class', 'btn btn-small');
     $shuffle->setAttrib('title', _('Shuffle playlist content'));
     $shuffle->setIgnore(true);
     $shuffle->setLabel(_('Shuffle'));
     $shuffle->setDecorators(array('viewHelper'));
     $this->addElement($shuffle);
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption" => $openSmartBlockOption, 'criteriasLength' => count($this->getCriteriaOptions()), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap, 'showPoolCount' => $showPoolCount))));
 }