Пример #1
0
 public function search()
 {
     $searchKey = new SearchKey();
     $this->tmpl->assign('htmlSearchKey', $searchKey->asHtml());
     if (!$searchKey->isGiven()) {
         return;
     }
     if ($searchKey->getOption() != 'random') {
         $this->createFeedLink($searchKey);
         $this->createSaveLink();
     }
     $serverPool = ExternalServerPool::activeServerPool();
     /*
      * Important order! ExternalBookListReader starts HTTP requests in the
      * constructor. The local database can be read while the external
      * servers are busy. Calling read(0) will read and parse the answers of
      * the servers.
      */
     $externalReader = new ExternalBookListReader($serverPool, $searchKey);
     $localBookList = new LocalSearchBookList($searchKey);
     $nearbyBookListArray = $externalReader->readNextGroup(0);
     if ($localBookList->size() || sizeof($nearbyBookListArray)) {
         $results = $this->tmpl->addSubtemplate('searchResults');
         $results->assign('HtmlRows', $localBookList->toHtmlRows());
         foreach ($nearbyBookListArray as $nearbyBookList) {
             $set = $results->addSubtemplate('nearbyResultSet');
             $set->assign('locationName', $nearbyBookList->locationName());
             $set->assign('HtmlRows', $nearbyBookList->toHtmlRows());
         }
     } else {
         /* Nothing found here, ask other servers group by group. */
         $externalBookListArray = $externalReader->readNextGroup(255);
         if (sizeof($externalBookListArray) == 0) {
             $this->tmpl->addSubtemplate('noResults');
             return;
         }
         $external = $this->tmpl->addSubtemplate('externalSearch');
         foreach ($externalBookListArray as $externalBookList) {
             $set = $external->addSubtemplate('externalResultSet');
             $set->assign('locationName', $externalBookList->locationName());
             $set->assign('HtmlRows', $externalBookList->toHtmlRows());
         }
     }
 }
Пример #2
0
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'books/SearchKey.php';
require_once 'notification/Searches.php';
require_once 'tools/Mailer.php';
$searchKey = new SearchKey();
if (!$searchKey->isGiven()) {
    header('Location: ./');
}
$mail = Mailer::mailFromUser('mail');
if ($mail == null) {
    $mail = Mailer::mailFromUser('name');
}
if ($mail) {
    $searches = new Searches();
    $searches->addSearch($searchKey->asText(), $mail);
    header('Location: ./?search=' . urlencode($searchKey->asText()) . '&searchSaved=1');
}
$tmpl = Template::fromFile("view/save_search.html");
$tmpl->assign('searchKey', $searchKey->asHtml());
$tmpl->assign('urlSearchKey', urlencode($searchKey->asHtml()));
$output = new Output();
$output->send($tmpl->result());