예제 #1
0
 public function executeUpload(sfWebRequest $request)
 {
     $target_list = $this->findTargetList();
     /* @var $target_list MailingList */
     if (!$target_list) {
         return $this->notFound();
     }
     if (!$this->getGuardUser()->isTargetListMember($target_list, true)) {
         return $this->noAccess();
     }
     $form1 = new ContactUploadStep1Form();
     $form2 = new ContactUploadStep2Form(array(), array('MailingList' => $target_list));
     if ($request->isMethod('post')) {
         if ($request->hasParameter($form1->getName())) {
             $form1->bind($request->getPostParameter($form1->getName()), $request->getFiles($form1->getName()));
             if ($form1->isValid()) {
                 $filename = $form1->save();
                 $form2->setSeparator($form1->getSeparator());
                 $form2->setFile($filename, true);
                 return $this->ajax()->replaceWithPartial('#upload_form', 'upload2', array('form' => $form2, 'target_list' => $target_list))->render(true);
             } else {
                 return $this->ajax()->form($form1)->render(true);
             }
         } else {
             $form2_params = $request->getPostParameter($form2->getName());
             $bind_ok = $form2->bind($form2_params);
             if (!$bind_ok) {
                 return $this->ajax()->alert('Critical error', '', '#upload_form .form-actions', 'before')->render();
             }
             if ($form2->isValid()) {
                 if ($form2->save()) {
                     $target_list->state(Doctrine_Record::STATE_DIRTY);
                     // to invalidate cache
                     $target_list->save();
                     return $this->ajax()->replaceWith('#upload_form', '<div id="upload_form"></div>')->alert('Upload successfull', '', '#upload_form', 'append')->replaceWithComponent('#contacts', 'target', 'contacts', array('target_list' => $target_list, 'page' => 1, 'no_filter' => true))->render();
                 } else {
                     return $this->ajax()->form($form2)->alert('Upload Error', '', '#upload_form .form-actions', 'before')->render();
                 }
             } else {
                 return $this->ajax()->form($form2)->render();
             }
         }
     }
     return $this->ajax()->replaceWithPartial('#upload_form', 'upload1', array('form' => $form1, 'target_list' => $target_list))->render();
 }