<commit_before><?php
    
    include 'sc-app.inc';
    include(APP_WEB_DIR . '/inc/header.inc');
    include(APP_WEB_DIR . '/inc/role/user.inc');

    use \com\indigloo\ui\form as Form;
    use \com\indigloo\Constants as Constants ;

    use \com\indigloo\exception\UIException as UIException;
    use \com\indigloo\exception\DBException as DBException;

    use \com\indigloo\sc\mysql as mysql;
    use \com\indigloo\sc\auth\Login as Login;
    use \com\indigloo\Url as Url ;

    use \com\indigloo\Util as Util ;
    use \com\indigloo\Logger as Logger ;

    // @imp submit buttons are only considered successful controls 
    // if they are used to submit the form
    // this form can be submitted using javascript also so do not include
    // submit_button_in_$_POST check.

    try{
        
        $fhandler = new Form\Handler("list-form-1", $_POST);
        //input rules
        $fhandler->addRule("qUrl", "go back to URL", array('required' => 1, 'rawData' =>1));
        $fhandler->addRule("item_id", 'item', array('required' => 1));
        
        $fvalues = $fhandler->getValues();

        $gWeb = \com\indigloo\core\Web::getInstance();
        $qUrl = base64_decode($fvalues["qUrl"]);
          
        if ($fhandler->hasErrors()) {
            throw new UIException($fhandler->getErrors());
        }

        $listId = $fvalues["list_id"] ;
        $itemId = $fvalues["item_id"];
        $loginId = Login::getLoginIdInSession(); 
        $flag = intval($fvalues["is_new"]);

        $listDao = new \com\indigloo\sc\dao\Lists();

        if( ($flag == 1) && empty($listId)) {
            // create new list 
            $name =  $fvalues["new-list-name"];
            if(!Util::isAlphaNumeric($name)) {
                $error = "Bad name : only letters and numbers are allowed!" ;
                throw new UIException(array($error));
            }

            $listDao->create($loginId,$name,$itemId);

        } else {
            //Add to existing list 
            $listDao->addItem($loginId,$listId,$itemId);
        }

        $message = sprintf("success! items added to list");
        $gWeb->store(Constants::FORM_MESSAGES,array($message));

        header("Location: " . $qUrl);


    }catch(UIException $ex) {
        $gWeb->store(Constants::STICKY_MAP, $fvalues);
        $gWeb->store(Constants::FORM_ERRORS,$ex->getMessages());
        header("Location: " . $qUrl);
        exit(1);

    }catch(DBException $ex) {
        Logger::getInstance()->error($ex->getMessage());
        Logger::getInstance()->backtrace($ex->getTrace());
        $gWeb->store(Constants::STICKY_MAP, $fvalues);

        $message = "Error: something went wrong with database operation" ;
        if($ex->getCode() == 23000) {
            $message =  sprintf("Error: list name _%s_ is already in use!",$name);
        }
        
        $gWeb->store(Constants::FORM_ERRORS,array($message));
        header("Location: " . $qUrl);
        exit(1);
<commit_msg> - Add view list link in list add success message!<commit_after><?php
    
    include 'sc-app.inc';
    include(APP_WEB_DIR . '/inc/header.inc');
    include(APP_WEB_DIR . '/inc/role/user.inc');

    use \com\indigloo\ui\form as Form;
    use \com\indigloo\Constants as Constants ;

    use \com\indigloo\exception\UIException as UIException;
    use \com\indigloo\exception\DBException as DBException;

    use \com\indigloo\sc\mysql as mysql;
    use \com\indigloo\sc\auth\Login as Login;
    use \com\indigloo\Url as Url ;

    use \com\indigloo\Util as Util ;
    use \com\indigloo\Logger as Logger ;
    use \com\indigloo\sc\util\PseudoId ;


    // @imp submit buttons are only considered successful controls 
    // if they are used to submit the form
    // this form can be submitted using javascript also so do not include
    // submit_button_in_$_POST check.

    try{
        
        $fhandler = new Form\Handler("list-form-1", $_POST);
        //input rules
        $fhandler->addRule("qUrl", "go back to URL", array('required' => 1, 'rawData' =>1));
        $fhandler->addRule("item_id", 'item', array('required' => 1));
        
        $fvalues = $fhandler->getValues();

        $gWeb = \com\indigloo\core\Web::getInstance();
        $qUrl = base64_decode($fvalues["qUrl"]);
          
        if ($fhandler->hasErrors()) {
            throw new UIException($fhandler->getErrors());
        }

        $listId = $fvalues["list_id"] ;
        $itemId = $fvalues["item_id"];
        $loginId = Login::getLoginIdInSession(); 
        $flag = intval($fvalues["is_new"]);

        $listDao = new \com\indigloo\sc\dao\Lists();
        $name =  $fvalues["new-list-name"];

        if( ($flag == 1) && empty($listId)) {
            // create new list 
            if(!Util::isAlphaNumeric($name)) {
                $error = "Bad name : only letters and numbers are allowed!" ;
                throw new UIException(array($error));
            }

            $listId = $listDao->create($loginId,$name,$itemId);
            $pListId = PseudoId::encode($listId);
        } else {
            //Add to existing list 
            $listDao->addItem($loginId,$listId,$itemId);
            $pListId = PseudoId::encode($listId);
        }


        $listUrl = str_replace(
            "{listId}",
            $pListId,
            "<a href=\"/pub/list/{listId}\">view list &rarr;</a>") ;


        $message = sprintf("success! items added to list. %s",$listUrl);
        $gWeb->store(Constants::FORM_MESSAGES,array($message));

        header("Location: " . $qUrl);


    }catch(UIException $ex) {
        $gWeb->store(Constants::STICKY_MAP, $fvalues);
        $gWeb->store(Constants::FORM_ERRORS,$ex->getMessages());
        header("Location: " . $qUrl);
        exit(1);

    }catch(DBException $ex) {
        Logger::getInstance()->error($ex->getMessage());
        Logger::getInstance()->backtrace($ex->getTrace());
        $gWeb->store(Constants::STICKY_MAP, $fvalues);

        $message = "Error: something went wrong with database operation" ;
        if($ex->getCode() == 23000) {
            $message =  sprintf("Error: list name _%s_ is already in use!",$name);
        }
        
        $gWeb->store(Constants::FORM_ERRORS,array($message));
        header("Location: " . $qUrl);
        exit(1);

{'fraction_non_alphanumeric': 0.15792828685258964, 'fraction_numerical': 0.004462151394422311, 'mean_word_length': 2.3329792883696228, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3690729', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1939, 'n_words': 405}